关于英语的问题:在标识符名称的第一部分中使用复数
作为一个非英语母语人士,我经常想知道在命名类或对象时在名词短语的开头部分使用复数形式。
例如:
如果我有一个连接多个[流媒体]播放器的接口,那么将其命名为
PlayersInterface
是很好的英语,而不是PlayerInterface
,后者是一个接口一个播放器?如果有一个处理事件的服务,可以将其命名为
EventsService
吗?或者EventService
听起来明显更好吗?
感谢您的帮助!
编辑:
显然,在 .NET 中,接口名称将以
I
开头。因此,让我们稍微更改一下示例,并将其命名为PlayersGateway
。我实际上没有另一个名为
PlayerInterface
(或PlayerGateway
)的类。这只是一个替代名称的示例,如果我只需要一个播放器的界面,我会使用它。我认为在同一个项目中同时使用PlayerGateway
和PlayersGateway
很难维护,更不用说对未来的团队成员有害了。因此,请假设没有PlayerGateway
,只有PlayerGateway
。
As a non-native English speaker, I often wonder about using the plural form in the initial part(s) of noun phrases when naming classes or objects.
For example:
If I have an interface to multiple [streaming] players, it is good English to name it
PlayersInterface
, as opposed toPlayerInterface
which is an interface to one player?If there is a service that handles events, is it ok to name it
EventsService
? Or doesEventService
sound significantly better?
Thank you for your help!
EDIT:
Obviously in .NET an interface name would start with an
I
. So let's change the example a bit and call itPlayersGateway
.I don't really have another class named
PlayerInterface
(orPlayerGateway
). It was just an example of an alternative name I would use if I only needed an interface to one player. I think that using bothPlayerGateway
andPlayersGateway
in the same project is hard to maintain, not to say evil to future team members. So please assume there is noPlayerGateway
, justPlayersGateway
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我的理解是,通常应该使用单词的单数短语。例如,如果您有一个 Car 类,并且您有一个包含 Car 类的许多实例的类,您可以将其称为 CarCollection 而不是 Cars
It is my understanding that you should generally use the singular phrasing of a word. For instance if you had a class Car, and you had a class that contained many instances of class Car you would call it CarCollection instead of Cars
在英语中,当你把一个名词放在另一个名词旁边来修饰它时,你通常使用单数:
即使房间里可能有几件外套或塔里有警卫。恕我直言,变量命名应该遵循语言的一般规则。
In English, when you stick a noun next to another noun to modify it, you usually use the singular:
even though there may be several coats in the room or guards in the tower. IMHO, variable naming should follow the general rules of the language.
我倾向于使用单数。 EventHandler 或 EventService 的含义是它将处理一个又一个事件。对于视频播放器,如果您说您正在连接到多个播放器并几乎同时控制所有播放器,我可能会相信。
对于单一情况,您是否有第二种类型/变量?
即便如此,我认为这两个类型名称太相似了。
但是,这是个人喜好。
I'd tend to use the singular. EventHandler or EventService would have the connotation that it would handle one event after another. For the video players, I might be convinced if you said that you were connecting to multiple players and controlling them all at pretty much the same time.
Would you have a second type/variable for the singular case?
Even then, I think the two type names are too similiar.
But, it's personal preference.
对于数据库中的类名和表名,单数形式通常更具有语义意义,因为每个实例(或数据库中的行)都是一个奇点。
您也可以对数组应用相同的推理。您可以选择将包[4] 视为#4 号包,而不是一堆包中的第4 号包。
恕我直言,EventService 和 PlayerInterface 是更好的名字,对英国人来说听起来更好。
Singular form often makes more semantical sense for class names and table names in databases, because each instance (or row in a database) is a singularity.
You can apply the same reasoning on arrays as well. You can chose to think of parcel[4] as parcel #4 and not number 4 of a bunch of parcels.
IMHO, EventService and PlayerInterface are better names that sound better to an english ear.