I've found that in programs, I inevitably have a couple of variables that are named along the lines of numberOfBooks
, or numberOfPeople
. Is there a commonly used word that makes sense that's a bit shorter than numberOf
?
Asked
Active
Viewed 373 times
0

Mike
- 19,267
- 11
- 56
- 72
-
1See also http://stackoverflow.com/questions/6358588/how-to-name-a-variable-numitems-or-itemscount . – Andy Thomas Feb 19 '12 at 04:05
-
In addition to being verbose, `numberOfBook` is ambiguous, because it could hold data like `ISBN 0-12345-67890-A` – phoog Feb 22 '12 at 19:20
3 Answers
3
Count or quantity are the usual suspects so you could get away with things like:
bookCount
bookQty
bookQuant
and so forth. But you don't have to use full words, as shown in the Qty
abbreviation above.
If you wanted to stay close to what the other programs are using, just use something like:
numBooks
numPeople

paxdiablo
- 854,327
- 234
- 1,573
- 1,953
-
Reasonable. Count seems acceptable in most contexts. I was hoping for some sort of "Mathy" word for the number of something. Maybe that's not a commonly used term, anyhow. – Mike Feb 18 '12 at 03:51
-
Well, a mathy word would be magnitude but I assumed you were after something a bit shorter :-) – paxdiablo Feb 18 '12 at 03:57
-
-
1Note that "num" is ambiguous. It could be a count, index or some other number. "Count" or "quantity" are more specific. – Andy Thomas Feb 19 '12 at 04:06
-
paxdiablo's suggestions are better than "mathy" equivalents, for the same reason that `numberOfBooks` is better than `n`: they provide contextual hints. One might even go further: `booksOnHand` is the number of books present in the classroom; `booksNeeded` is the number of books required for the students taking the class; `booksToOrder` fills out the gap between the two, possibly taking into account differing sizes of other class instances that will share the books. That they are numbers is implied by declaring them as `int`s, a fact most IDEs make easy to learn on demand. – Ross Patterson Feb 19 '12 at 15:38