Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

This question is about your opinions and/or existing conventions.

Let's say I have an object Basket that store various items in some private property (Basket._items). Now, I want to have a couple of methods for adding, removing and getting items.

Each method can take either a single item or a list of items as an argument, or with no arguments, in the case of removing and getting, may remove or return all items.

How do you think I should name my methods?

addItem or addItems
removeItem or removeItems
getItem or getItems

(They don't all have to be the same form; for instance, maybe only the last one should be plural.)

share|improve this question

closed as off topic by Glenn Rogers, Paul, Brian Reichle, Jeff Vanzella, Yannis Oct 5 '12 at 20:08

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

If the methods add, get and remove multiple items, I'd use a plural. I think it's more obvious that addItems can add one item than addItem can add multiple items.

In any case, good documentation is your ally. :-)

share|improve this answer

Why do you have to use overloading here? I would use both names; the plural for the list, and the singular for the element. Write 6 methods, and be clear about whether you expect an array or element for each.

Also, can a bucket hold anything else? If not, I would prefer the simpler "add", "remove", "list", and "get".

share|improve this answer
Unfortunately, the Basket object does hold other things. I guess using both is an option - but wouldn't you say it goes against the conventions of jQuery, just to give an example? Also, when adhering to the DRY principle, both functions would delegate to the same body of code, which might seem clumsy. –  dalgard Oct 4 '12 at 3:21
Even if you do it in the same method, you will have to branch on list or element somehow, right? Your pluralized method can be very thin, iterating over the list and delegating to the singular method. –  corykendall Oct 4 '12 at 5:35

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