86

English is not my native language and I can't understand how to write the specified samples right. When you say something what aggregates plural object such as "collection of stamps" you can say alternatively: "stamps collection", am I right? If you will say "stamp collection" it will mean some "collection" which is a single "stamp".

But often I see classes with names like "ItemList" - doesn't it mean that such class is a list which is an item of something else? Such sample is more flaring:

class ItemList: List<Item>

Isn't it have to be so?:

class ItemsList: List<Item>

Why is it rarely written so? Or is it some programming languages naming convention? Or just proper english sentences? :)

11
  • 53
    @WeaselFox: Some people have a deep-seated, healthy curiosity about the world around them, and are keen to learn. If you are not one of these people, then you're free to ignore this question. Mar 20, 2012 at 10:32
  • I am no native english speaker as well, so take my comment with a grain of salt. I'd prefer ItemList over ItemsList, as the term List already contains the notion of multiple contained objects.
    – evnu
    Mar 20, 2012 at 10:32
  • Possibly because Item is the name of the class being stored in the list.
    – BoBTFish
    Mar 20, 2012 at 10:33
  • Slav, in reality, stamp collection is correct not stamps collection that's why ItemList is used also.
    – Shahbaz
    Mar 20, 2012 at 10:37
  • 16
    In English, we're always turning nouns into adjectives that modify other nouns, and we use the singular noun when we do. "Sweet shop", "candy store", "duck pond", "prawn sandwich", "piano tuner". That's why a collection of stamps is called a "stamp collection" in English. "Stamp collection" would never mean specifically a collection of one stamp, except perhaps as a humorous device (Terry Pratchett wrote a book that mentioned a Plague of Frog). Or very pedantically some "stamp collection" might happen to contain only one stamp, but you usually wouldn't call that a collection in English. Mar 20, 2012 at 10:43

3 Answers 3

64

In English, a "collection of stamps" is a "stamp collection". (At best, "stamps collection" would be understood).

In programming, I'm not entirely sure why, but we1 do sometimes use the form "StampsCollection".

It may be because we try to use more precise and logical lingo than traditional English provides; we start with the name "Item", pluralise it to "Items", then be precise by stating that our collection of "Items" is a "List" rather than an "Array" or some other implementation.

You're likely to see both variants, though, and it doesn't really matter.

Certainly, neither in English nor in programming would ItemsList imply a list of collections of Items, at least not to most people.


1 ... for some value of "we". Naming choices are, of course, down to personal preference. However, I've personally seen this as a tendency.

8
  • 4
    "we do tend to use the form "stamps collection" instead" - FWIW, I don't. I'd call it either stampCollection or stamps. Personally I don't recall seeing stampsCollection much, but that might just be a quirk of the dialect (both English and programming-language) of the colleagues I've had. Mar 20, 2012 at 10:35
  • @SteveJessop: I suppose there's no way to make an answer either way there. We're certainly more likely to see it in programming than in real English. Mar 20, 2012 at 10:38
  • Perhaps I'm wrong to read what you wrote this way, but I read "tend to do X" as meaning, "do X more often than not X". Which I think I disagree with in this case, but obviously I can't say whether you've observed that tendency in the code you've read :-) Even worse, one of the problems lexicographers face, and that we face here, is distinguishing variant usage from usage that is intentional at time of writing, but "incorrect". Mar 20, 2012 at 10:50
  • @SteveJessop: You read it right. I guess I'm abusing the word "we". Mar 20, 2012 at 10:53
  • OK, we're certainly agreed that it happens, and that you have to be able to read both conventions. Mar 20, 2012 at 11:00
11

I find ItemList much more descriptive. It is a list of objects of type Item.

On the other hand, if you had a collection of Item objects, you could call it Items, and ItemsList would designate a list of collections.

4
  • 5
    I would not expect ItemsList to be a list of collections. Mar 20, 2012 at 10:32
  • @LightnessRacesinOrbit me neither. But say someone else did typedef std::vector<Item> Items. How would you call std::list<Items>? Mar 20, 2012 at 10:34
  • I would typedef Items ItemsArray and then typedef std::list<ItemsArray> ItemsArraysList, whilst stabbing the original author in the face Mar 20, 2012 at 10:35
  • It occurs to me also that you could also get to itemsList via some form of Hungarian notation. The object is your items, and its type is List. Not very nice, but nevertheless half-assed Hungarian notations aren't that unusual. Mar 20, 2012 at 10:45
1
class Items: List<Item>

And more readable, in general I do a typedef

// C++98
typedef List<Item> Items;

// since C++11 you can write it also this way, and I prefer this:
using Items = List<Item>;

It is often good practice (clean code) to think about a more specialized class that hides the List. "Prefer composition by aggregation over inheritance" is common idiom in OOP (quoting Sutter/Alexandrescu: C++ Coding Standards: 101 Rules, Guidelines, and Best Practices)

Encapsulation of a collection is most of the time a good practice which lowers the complexity of calling code:

class Encapsulation
{
    Items m_items;
    public: 
    void AddItem(const Item&);
    void RemoveAllItems();
    // ... all the functions about managing the List that would be otherwise boilerplate code spread all over your codebase
}

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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