Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to name a variable: numItems or itemCount?

What is the right way to name a variable

int numItems; 

vs.

int itemCount; 

or constant:

public static final int MAX_NUM_ITEMS = 64; 

vs.

public static final int MAX_ITEM_COUNT = 64; 
like image 836
Pavel Alexeev Avatar asked Jun 15 '11 13:06

Pavel Alexeev


People also ask

Which is a good example of a variable name?

Variable names are shown in green color in the questionnaire Designer. The following are examples of valid variable names: age, gender, x25, age_of_hh_head. The following are examples of invalid variable names: age_ (ends with an underscore);


2 Answers

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."

like image 119
Andy Thomas Avatar answered Oct 10 '22 00:10

Andy Thomas


item_count or itemCount (there's a religious war brewing there, though)

like image 38
William Pursell Avatar answered Oct 09 '22 23:10

William Pursell