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

发布于 2024-10-18 01:17:06 字数 763 浏览 7 评论 0原文

作为一个非英语母语人士,我经常想知道在命名类或对象时在名词短语的开头部分使用复数形式。

例如:

  • 如果我有一个连接多个[流媒体]播放器的接口,那么将其命名为 PlayersInterface 是很好的英语,而不是 PlayerInterface,后者是一个接口一个播放器?

  • 如果有一个处理事件的服务,可以将其命名为EventsService吗?或者 EventService 听起来明显更好吗?

感谢您的帮助!

编辑:

  1. 显然,在 .NET 中,接口名称将以 I 开头。因此,让我们稍微更改一下示例,并将其命名为 PlayersGateway

  2. 我实际上没有另一个名为PlayerInterface(或PlayerGateway)的类。这只是一个替代名称的示例,如果我只需要一个播放器的界面,我使用它。我认为在同一个项目中同时使用 PlayerGatewayPlayersGateway 很难维护,更不用说对未来的团队成员有害了。因此,请假设没有 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 to PlayerInterface which is an interface to one player?

  • If there is a service that handles events, is it ok to name it EventsService? Or does EventService sound significantly better?

Thank you for your help!

EDIT:

  1. Obviously in .NET an interface name would start with an I. So let's change the example a bit and call it PlayersGateway.

  2. I don't really have another class named PlayerInterface (or 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. So please assume there is no PlayerGateway, just PlayersGateway.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

有木有妳兜一样 2024-10-25 01:17:06

我的理解是,通常应该使用单词的单数短语。例如,如果您有一个 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

快乐很简单 2024-10-25 01:17:06

在英语中,当你把一个名词放在另一个名词旁边来修饰它时,你通常使用单数:

 Coat Room
 Guard Tower

即使房间里可能有几件外套或塔里有警卫。恕我直言,变量命名应该遵循语言的一般规则。

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.

玉环 2024-10-25 01:17:06

我倾向于使用单数。 EventHandler 或 EventService 的含义是它将处理一个又一个事件。对于视频播放器,如果您说您正在连接到多个播放器并几乎同时控制所有播放器,我可能会相信。

对于单一情况,您是否有第二种类型/变量?

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

即便如此,我认为这两个类型名称太相似了。

但是,这是个人喜好。

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?

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.

对于数据库中的类名和表名,单数形式通常更具有语义意义,因为每个实例(或数据库中的行)都是一个奇点。

您也可以对数组应用相同的推理。您可以选择将包[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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文