How to name a variable: numItems or itemCount?

前端 未结 5 494
暖寄归人
暖寄归人 2021-02-01 17:01

What is the right way to name a variable

int numItems;

vs.

int itemCount;

or constant:

public         


        
5条回答
  •  旧巷少年郎
    2021-02-01 17:22

    It actually depends on you. The two types of naming conventions are camelCase and snake_case

    As you can identify from the naming, camel case has one small letter in the initial part of the variable followed by the Capital words

    Eg itemCount.

    snake case is a continuous word with an underscore ' _ ' in between the words Eg item_count

    As far as the naming is concerned, numItems is quite confusing for others to read. But itemCount is a good name for a counter variable

提交回复
热议问题