简体   繁体   English

关于英语的一个问题:在标识符名称的第一部分使用复数

[英]Kind of a question about the English language: Using plural in the first part of an identifier name

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 to PlayerInterface which is an interface to one player? 如果我有多个[流媒体]播放器的界面,那么将它命名为PlayersInterface是好的英语,而不是PlayerInterface ,它是一个播放器的接口?

  • If there is a service that handles events, is it ok to name it EventsService ? 如果有一个处理事件的服务,可以将它命名为EventsService吗? Or does EventService sound significantly better? 或者EventService声音明显更好?

Thank you for your help! 谢谢您的帮助!

EDIT: 编辑:

  1. Obviously in .NET an interface name would start with an I . 显然在.NET中,接口名称将以I开头。 So let's change the example a bit and call it PlayersGateway . 所以让我们稍微改变一下这个例子并称之为PlayersGateway

  2. I don't really have another class named PlayerInterface (or PlayerGateway ). 我真的没有另一个名为PlayerInterface (或PlayerGateway )的类。 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 both PlayerGateway and PlayersGateway in the same project is hard to maintain, not to say evil to future team members. 我认为在同一个项目中使用PlayerGatewayPlayersGateway很难维护,更不用说对未来的团队成员来说是邪恶的。 So please assume there is no PlayerGateway , just PlayersGateway . 所以请假设没有PlayerGateway ,只有PlayersGateway

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 例如,如果您有一个类Car,并且您有一个包含许多Car类实例的类,您可以将其称为CarCollection而不是Cars

In English, when you stick a noun next to another noun to modify it, you usually use the singular: 在英语中,当你将名词贴在另一个名词旁边修改它时,通常使用单数:

 Coat Room
 Guard Tower

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. 恕我直言,变量命名应遵循语言的一般规则。

I'd tend to use the singular. 我倾向于使用单数。 EventHandler or EventService would have the connotation that it would handle one event after another. EventHandler或EventService具有它将处理一个又一个事件的含义。 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? 你会为单数情况提供第二种类型/变量吗?

PlayersInterface AllPlayers = new PlayersInterface();
PlayerInterface MyPlayer0 = AllPlayers.getPlayer(0);
PlayerInterface MyPlayer2 = AllPlayers.getPlayer(1);

Even then, I think the two type names are too similiar. 即便如此,我认为这两个类型的名字太相似了。

But, it's personal preference. 但是,这是个人偏好。

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. 您可以选择将parcel [4]视为包裹#4而不是一堆包裹中的第4个。

IMHO, EventService and PlayerInterface are better names that sound better to an english ear. 恕我直言,EventService和PlayerInterface是更好的名字听起来更好的英语耳朵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM