返回列表的方法中的复数/单数命名
这似乎是一个微不足道的问题,直到你意识到你需要一致性。作为一个非英语母语人士,我更喜欢同时询问语法和风格。在这些方法名称中必须首选哪一个,返回一组 URI,每个 URI 都与一个对象相关联?
objectUriList()
objectsUriList()
objectUrisList()
objectsUrisList()
另外,您是否认为良好的风格可以明确表明返回的对象是方法名称中的列表。也许像 objectUris()
(或其正确形式)这样的东西在任何情况下都会很好并且直观。
it seems a trivial point, until you realize that you need consistency. Not being a native English speaker, I prefer to ask both for grammar and for style. Which one must be preferred among these method names, returning a list of URIs, each one associated to an object?
objectUriList()
objectsUriList()
objectUrisList()
objectsUrisList()
Also, do you consider good style to make explicit that the returned object is a list in the method name. Maybe something like objectUris()
(or its correct form) would be fine and intuitive in any case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我也不是以英语为母语的人。正确的形式是 objectUriList 或 objectUris。无论对象和uri的数量有多少。
停车场=汽车停车场。
PC存储=PC的存储。
橡树林
ETC。
I am not a native English speaker either. Correct form is either objectUriList or objectUris. Regardless of the number of objects and uris.
Car park = park of cars.
PC storage = storage of PCs.
oak forest
etc.
我会称之为 objectUriList(),它只是说起来更容易并且本质上是正确的。很明显,它返回一个 List,它是一组 Uris,因此您实际上不需要复数。
但是,您对 objectUris() 的最终建议也很好,具体取决于在您的 IDE 中看到它返回 List 的容易程度。
I would call is objectUriList(), it's just easier to say and essentially correct. It's clear that it returns a List which is a set of Uris, so you don't really need the plural there.
However, your final suggestion of objectUris() is also good, depending on how easy it is to see that it returns a List in your IDE.
objectUriList 应该是正确的答案。
(除非该函数在多个对象上运行,否则objectsUriList 会更好)。
我喜欢在函数名称中指定返回的对象,但因为这就是我一生的工作方式(自从更糟糕的编程语言以来)。如今,我认为没有必要了。
objectUriList should be the correct answer.
(Unless the function runs on more than one object and then objectsUriList would be preferable).
I like to specify the returned object in the function name but because this is how I worked for my entire life (ever since crappier programming languages). Nowadays, I believe it's not necessary.
最好使用
ObjectUriList
。在某些圈子中建议不要在成员/参数名称中包含类型名称,因此您应该删除 List 部分,但我发现“ObjectUriList”比“ObjectUris”更明确和有意义,尤其是当您也可能附近有“ObjectUri”作为名称。
It's better to use
ObjectUriList
.It is recommended in some circles not to include type names in member/parameter names, so you should drop the List part, but I find that "ObjectUriList" is much more explicit and meaningful than "ObjectUris", especially when you are likely to also have "ObjectUri" as a name nearby.
我肯定会选择
objectUris()
替代方案,省略“List”后缀。正如你所说,整洁且直观。I would definitely go with the
objectUris()
alternative, omitting the "List" suffix. As you say, tidy and intuitive.我认为为了区分数组和列表,最好在数组后面加上“s”,在列表后面加上“list”。
I think to differentiate between Array and List, It's good to append Array with 's' and List with 'list'.
我通常尝试使用单数名称空间,但有时也会根据上下文使用复数名称空间。例如,如果您的返回总是复数(例如某些关键字),我会使用复数,但如果它经常是单数,我会坚持单数命名约定。
I usually try to go with singular namespaces but sometimes and contextually plural namespaces as well. For e.g. if your return is always plural such as some keywords, I go with plural but if it can be singular often times, I stick to singular naming convention.