views:

55

answers:

3

I have a quick question that is not particular technical, but I sometimes wonder what's better ...

Do you use singular or plural in names of arrays, maps, sets, etc.? Example:

Singular

1  std::map<string,double> age;
2  age["diego maradonna"] = 49;

Plural

1  std::map<string,double> ages;
2  ages["diego maradonna"] = 49;

In the plural version, the second line isn't nice (because you're looking up the age, not the ages of Maradonna). In the singular version, the first line sounds kind of wrong (because the map contains many ages).

A: 

Singular for instances, plural for collections.

Andrew
A: 

Plurals. I use the same kind of names for SQL tables. The case of:

ages["diego maradonna"] = 49;

should be read as "in the collection of ages, find me the one that belongs to maradonna and change it to 49"

anon
A: 

For maps, I will typically even go a step further and name them in terms of both their keys and values (ex. agesByPersonNames). This is especially helpful if you have a map of maps.

btreat