6

It's a language agnostic question. Seems like a common problem, but I can't find answer anywhere.

I need to pick a name for a variable to hold the values of one attribute of a list of objects, and I would like the variable's name contain the attribute name as well as the object's name. My question is how to use the plural forms correctly within the variable name.

For example, for storing the names of some companies from a list, imagine some pseudo code like this:

string[] x = companies.map(p => p.name);
// or
string[] x = companies.select(p => p.name);
// or
string[] x = companies.getNames();

And the question is: what should be the name of x array?

a) companiesNames - (two plurals)

b) companiesName - (plural + singular)

c) companyNames - (singular + plural)

closed as primarily opinion-based by gnat, amon, Jörg W Mittag, Thomas Owens Mar 23 '17 at 13:11

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    People are voting to close the topic because of two things: first, the question is essentially asking which of the three choices states is grammatically sound, which makes it more of an English or ELL.SE question than an SE.SE question. Second, grammar aside, there isn't really a correct way to approach this, as while most people would use C, some would use A or B. It's a matter of preference, which makes the question highly opinionated and in turn off-topic for SE.SE. – Revenant Mar 23 '17 at 7:25
  • 1
    Picking a specific name for a variable is IMHO too opinionated for this site. But if you can reword the question in a more general fashion and clarify your "company" "name" is just an example for the more general type of problem, you might improve the chances of this question not to be closed (but I cannot give you a warranty on this). – Doc Brown Mar 23 '17 at 7:43
  • 1
    I disagree that this is opinion-based. A list of names of companies would almost certainly be spoken of as "the list of company names", and not as the *"list of companies names" or the *"list of company name". Therefore the variable should be named like this as well. – Kilian Foth Mar 23 '17 at 8:07
  • 1
    @andrew.fox: don't know why you ignored my comment above (I am sure you have seen it), so I took the freedom to reword your question by myself. If I did not get something right, feel free to revoke my edit, or improve the question by yourself. – Doc Brown Mar 23 '17 at 8:34
  • 1
    PS. For some commenters it might not be obvious that most programmers aren't native English speakers. So for them (and me) it's difficult to say which form "sounds" better is or more correct grammatically. In Polish language two plurals sounds better. In English it's otherwise. – andrew.fox Mar 23 '17 at 8:42
7

Variable names should be grammatically correct (and spelled correctly), unless you have a compelling reason to do otherwise. So companyNames.

I you are in doubt, just think about what you would write in prose, eg, in an explanatory comment. "x is a list of company names" or "x is a list of names of companies" - but (hopefully) not "x is a list of companies names".

You probably get companiesNames and companiesName because you think of how the data is generated from a variable called companies. But when naming variables you shouldn't base it on how you got the value, but rater the meaning of the value itself.

0

To offer an alternative, add Of to make the matter a little clearer:

CompanyID => A unique immutable identifier for a single company

CompanyIDs => A list of the above

NamesOfCompany => A list of the trading names, current &/or historic, of a single company.

NamesOfCompanies => A list of the above lists of names of several companies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.