开发者

Plural/singular naming in methods returning lists

it seems a trivial point, until you realize that you need consistency. Not being a native English speaker, I prefer to ask both for grammar and for style. Which one must be preferred among these method names, returning a list of URIs, each one associated to an object?

objectUriList()
objectsUriList()
objectUrisList()
objectsUrisList()
开发者_StackOverflow

Also, do you consider good style to make explicit that the returned object is a list in the method name. Maybe something like objectUris() (or its correct form) would be fine and intuitive in any case.


I am not a native English speaker either. Correct form is either objectUriList or objectUris. Regardless of the number of objects and uris.

Car park = park of cars.
PC storage = storage of PCs.
oak forest
etc.


I would call is objectUriList(), it's just easier to say and essentially correct. It's clear that it returns a List which is a set of Uris, so you don't really need the plural there.

However, your final suggestion of objectUris() is also good, depending on how easy it is to see that it returns a List in your IDE.


objectUriList should be the correct answer. (Unless the function runs on more than one object and then objectsUriList would be preferable).

I like to specify the returned object in the function name but because this is how I worked for my entire life (ever since crappier programming languages). Nowadays, I believe it's not necessary.


I would definitely go with the objectUris() alternative, omitting the "List" suffix. As you say, tidy and intuitive.


It's better to use ObjectUriList.

It is recommended in some circles not to include type names in member/parameter names, so you should drop the List part, but I find that "ObjectUriList" is much more explicit and meaningful than "ObjectUris", especially when you are likely to also have "ObjectUri" as a name nearby.


I think to differentiate between Array and List, It's good to append Array with 's' and List with 'list'.


I usually try to go with singular namespaces but sometimes and contextually plural namespaces as well. For e.g. if your return is always plural such as some keywords, I go with plural but if it can be singular often times, I stick to singular naming convention.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜