In English, the words “number” and “count” can act as nouns or verbs, but it is probably more common to see a “number” used as a noun and “count” as a verb. Therefore, you can argue that “foos number” or “num_foo” sounds more familiar than “counting foo” or “foo_count”. This certainly sounds more natural to me when it refers to a quantity that does not change constantly. The word "account", even if it is used as a noun, offers me a meaning that grows with time.
Ruby and Python have .count methods that demonstrate that a word is used as a verb, not a noun. In Ruby, you can say:
foos.count
However, this returns a value representing the number of foos, and this is exactly what you would expect if you just specified a variable called foo_count. So, in a sense, the fact that foos.count and foo_count look the same looks nice.
A "number" may be ambiguous in some cases, since it is common to store numbers that do not represent the quantity of something. Other people have already mentioned identifiers and credit card numbers. Here is another example:
num_string
Looking at this variable name, can you guess what it represents? Is this an integer representing the number of lines, or is it a string representation of the number?
So, I just think out loud and give some pros and cons for everyone, as I see them. The reason I am even on this old page is because I find that I use these two inconsistently, and thought I would see what other people are doing.
By the way, I do not like "nr_foo" because "nr" really does not offer or does not sound like the word "number" for me at all. It sounds like “ner,” or perhaps it means “not rated” or “national rugby." :-) And I won’t even dare say what fooCnt is. Simply no.
Kal Dec 31 '14 at 15:10 2013-12-31 15:10
source share