How to name a variable: numItems or itemCount?

前端 未结 5 453
暖寄归人
暖寄归人 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:36

    In "Code Complete," Steve McConnell notes that "Number" is ambiguous. It could be a count, or an index, or some other number.

    "But, because using Number so often creates confusion, it's probably best to sidestep the whole issue by using Count to refer to a total number of sales and Index to refer to a specific sale."

提交回复
热议问题