views:

85

answers:

7

Let's suppose that I need to store the number of foo objects in a variable.

Not being a native English speaker, I always wonder what's the best (= short and immediately clear) name for that var.

foo_num? num_foo? no_foo? foo_no? or something else?

The full name should be number_of_foos, but it's a bit verbose.

What's your favorite and why?

+3  A: 

Since the variable stores the count of the number of foo objects, fooCount gets my vote.

Justin Niessner
+1 for adding a rationale (although the phrasing is rather inelegant).
delnan
@delnan - Normally I would elaborate but I'm answering from my phone.
Justin Niessner
A: 

I'd go for fooCount

CyberDude
A: 

I tend to use fooCount or similar.

Engin Kurutepe
+1  A: 

fooCount if the variable isn't a constant, FOO_COUNT if it is. :D

CrazyJugglerDrummer
+1  A: 

The Linux kernel uses "nr_foo", which is better than "no_foo" (that looks like a negation). I myself tend to use "fooCount" or "fooCnt", but also sometimes "numFoo". I'm not sure why I vacillate between "fooCount" and "numFoo". Guess it depends on my mood. But you, you should be consistent (as should I) ;)

siride
I like `nr_foo`, thanks.
rjack
@rjack - "number" is vague, "count" is specific. A number could be an ID, for example. [I think McConnell makes this point in "Code Complete," but I don't have a copy with me.] Abbreviations of "number" more likely understood (other than by Linux kernel writers) include "nFoo" and "numFoo."
Andy Thomas-Cramer
@Andy Thomas-Cramer - Not so confusing IMHO: `credit_card_nr` sounds like "credit card number", while `nr_credit_cards` sounds like "number of credit cards" and it's shorter than `credit_cards_count`. Sounds quite natural to me (but I may be wrong since I'm not a native english speaker).
rjack
@rjack It would be credit_card_count anyway, since you don't generally pluralize nouns when they are part of a compound.
siride
@siride thanks for the observation
rjack
A: 

Mostly fooCount like everybody said. Sometimes it is more appropriate to use foos, usually when you don't actually have the list of foos, or they aren't separate objects (e.g. seconds; for a pizza you can have slices, etc.)

Only use foos when there's no chance of confusion though - when it's obvious that you'd never have a list of foos in this context.

configurator
If you use `foos` sometimes to mean "the number of `foo` objects" and other times to mean "the collection of `foo` objects, I'd think that could lead to confusion.
James McNellis
`slices` sounds to me like an array of `slice` objects, that are part of a `pizza` object. I'd use `sliceCount`, or `nr_slices`, or whatever (I haven't decided yet :D)
rjack
Yes, only use that when there's no chance of condusion
configurator
A: 

Foo, bar, fred, wilma, barney, betty, pebbles, bambam.

Cylon Cat