13

Especially in IT it is often neccessary to write chains of nouns like messages list because one cannot use list of messages for a variable name in a programming language.

I can't understand how to construct them correctly for plurals, for example is it a "message list" or "messages list"? What grammar rules concern this subject?

As a maybe special case, I'm interesting in naming the number of something, for example the number of apples. It is common to use "apple count" (although count means counting, not quantity). What is right, "apple count" or "apples count", and why?

I found a little bit similar question. Maybe both forms are allowed?

tchrist
  • 134,759
Yury
  • 251
  • 2
  • 5
  • Why do you think it is somehow impossible to use noun phrases like list_of_messages instead of only compound nouns like message_list in a programming context? People do this all the time by using full phrases in real English, whether that means Verb Phrases for function names like tentatively_mark_messages_for_deletion, or Noun Phrases for variable names like messages_marked_for_deletion or even expired_messages_marked_for_deletion_after_midnight. Sticking as close to real English as possible for identifiers *greatly* improves code readability! – tchrist Sep 06 '21 at 13:23

2 Answers2

11

Using the plural would be odd, if not outright wrong.

  • A list of messages is a message list, not a messages list.
  • A trap for mice is a mouse trap, not a mice trap.
  • A catcher of flies is a flycatcher, not a fliescatcher.
  • Determination of types of compound nouns is compound noun type determination, not compound nouns types determination.
3

There are plenty of discussions about this topic already, which could be considered a grey area between English and programming, I guess.

As an English-speaking programmer, I'd suggest that such names would generally contain singular nouns, such as messageList and appleCount in your case (capitalisation is a whole other issue and possibly a massive can of worms!)

The general idea behind naming things in this way is so that other people (and you in the future) can understand what's going on at a glance. I've had to work with C++ code with single-letter variable names (ostensibly chosen for compiler efficiency) and it's not pleasant.

So as long as the code is clear, then I'm not sure it matters too much. You could actually have theListOfMessages, but you're going to be typing more and could 'clutter' the code. Try to keep them short and meaningful. If you're doing this professionally, your employer may well have their own guidelines which could indeed contradict some of my comments above.

  • 1
    Although incorrect , I have used "merchandises" in my code, just to imply that it is a one to many relationship. My coworkers have found it helpful. I suspect this question will be marked irrelevant but that's my two cents for you. – hungryKoala Feb 19 '15 at 18:43
  • @Ritu : That's a good point. Languages like Ruby actively encourage this convention, I believe. (I've never used it). – Robin Williams Feb 19 '15 at 18:53
  • I think this answers a different question. – reinierpost Dec 11 '15 at 09:35