![Creative The name of the picture]()

Clash Royale CLAN TAG#URR8PPP
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;
4 Answers
4
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."
item_count or itemCount (there's a religious war brewing there, though)
For Java I would use itemCount and MAX_ITEM_COUNT. For Ruby, item_count and MAX_ITEM_COUNT. I tend not to use names that can be interpreted wrongly (numItems may be a shortcut for numerate_items or number_of_items), hence my choice. Whatever you decide, use it constantly.
itemCount
MAX_ITEM_COUNT
item_count
MAX_ITEM_COUNT
numItems
numerate_items
number_of_items
numerate
It's a matter of personal preference, just make sure you are consistent throughout your code. If you're working with others check what's been done in existing code.
For the constant I would find MAX_ITEMS more logical than MAX_NUM_ITEMS or similar, it just sounds better to me.
MAX_ITEMS
MAX_NUM_ITEMS
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Any time you're about to ask a question about the "right" way to do something, stop and consider whether it's merely a subjective, aesthetic preference. This certainly qualifies. It absolutely doesn't matter. Pick one that you like and stick with it.
– Cody Gray♦
Jun 15 '11 at 14:05