数组、映射、集合等的名称使用单数还是复数?
我有一个不是特别技术性的快速问题,但我有时想知道什么更好......
您在数组、映射、集合等名称中使用单数还是复数?示例:
单数
1 std::map<string,double> age;
2 age["diego maradonna"] = 49;
复数
1 std::map<string,double> ages;
2 ages["diego maradonna"] = 49;
在复数版本中,第二行不太好(因为您查找的是年龄,而不是马拉多纳的年龄)。在单数版本中,第一行听起来有点错误(因为地图包含许多时代)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实例用单数,集合用复数。
Singular for instances, plural for collections.
对于地图,我通常会更进一步,根据它们的键和值来命名它们(例如,agesByPersonNames)。如果您有地图,这尤其有用。
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.
复数。我对 SQL 表使用相同类型的名称。案例:
应该理解为“在年龄集合中,给我找到属于马拉多纳的那个,并将其更改为49”
Plurals. I use the same kind of names for SQL tables. The case of:
should be read as "in the collection of ages, find me the one that belongs to maradonna and change it to 49"
我会使用 nameToAgeMap["diego maradonna"],所以很明显你输入的内容(名字)和取出的内容(年龄),它在作业中读起来很好:
nameToAgeMap["diego maradonna"] = 49;
可以理解为“将 49 放入迭戈·马拉多纳的姓名到年龄映射中”。I would use
nameToAgeMap["diego maradonna"]
, so it's obvious what you put in (a name) and get out (an age), it reads nicely in assignments:nameToAgeMap["diego maradonna"] = 49;
which could be read as "put 49 into the name-to-age map for Diego Maradonna".