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

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

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

disc

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

Multiple

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

In the plural version, the second line is not very pleasant (because you are looking at the age, not the age of Maradonna). In a single version, the first line does not sound right (because the card contains many ages).

+7
variables naming-conventions
source share
4 answers

Singular for instances, multiple for collections.

+2
source share

For cards, I usually even take a step further and call them both in terms of their keys and values ​​(e.g. ageByPersonNames). This is especially useful if you have a map card.

+2
source share

nouns. I use the same names for SQL tables. Happening:

 ages["diego maradonna"] = 49; 

should read like "in the collection of centuries, find me the one that belongs to the maradonna, and change it to 49"

+1
source share

I would use nameToAgeMap["diego maradonna"] , so the explicit thing is that you enclosed (name) and exit (age), it reads well in assignments: nameToAgeMap["diego maradonna"] = 49; , which can be read as "put 49 in the name - (" Diego Maradonna ").

+1
source share

All Articles