naming-cheatsheet icon indicating copy to clipboard operation
naming-cheatsheet copied to clipboard

Use of singular/plurals for compound terms

Open octavian-nita opened this issue 3 years ago • 2 comments

I'd suggest a convention regarding the use of singular/plurals if only I knew how to formulate it in English properly :) Hopefully, someone has a good English formulation to replace mine.

The idea is to pay attention to what noun in a (more-or-less) compound term we employ in plural form when naming things with multiple values. I.e., just as we use, say, documentTypes, I think we should most probably use childPaths instead of childrenPaths, etc.

I've seen this (i.e., using the plural form for all nouns in such composed term) happening a lot and I don't quite agree with it.

octavian-nita avatar Mar 05 '21 16:03 octavian-nita

Hi, @octavian-nita. Thank you for this suggestion! I think you've formulated it beautifully.

Would this also apply to cases when multiple segments of the variable are changed to plurals while only the last (?) bit should be plural?

-postsLinks
+postLinks

kettanaito avatar Jul 09 '22 14:07 kettanaito

Hi @kettanaito,

Indeed, I would say so, yes.

There may be situations where keeping several plurals might make sense, depending on what the developer wants to convey. In your example, I would understand "postLinks" as referring to the collection of links of a particular post, but someone else could use "postsLinks" to refer, for example, to all the links of all the posts. However, I would still not use "postsLinks" for that :). Instead, I would probably use "allPostLinks" or something else. Or another example would be when we have a map/dictionary that associates many entities, like posts and their links. There, we might use "postsLinks" for brevity, but I'd still make an effort to write "postsToLinks" or "postsAndLinks."

So yes, I generally favor only one word/segment in the plural form, and I'd recommend much care with several words in plural.

octavian-nita avatar Jul 11 '22 07:07 octavian-nita