escargot agile
escargot agile

Reputation: 22389

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:

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.

Upvotes: 5

Views: 289

Answers (4)

MattBianco
MattBianco

Reputation: 1531

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.

Upvotes: 1

dandan78
dandan78

Reputation: 13864

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.

Upvotes: 6

Tom Cerul
Tom Cerul

Reputation: 1943

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.

Upvotes: 1

Brent
Brent

Reputation: 1388

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

Upvotes: 8

Related Questions