开发者

How to name an array that already has a plural name?

开发者 https://www.devze.com 2023-03-23 11:01 出处:网络
What do you name your arrays when the name of the item is already plural? array names makes开发者_JAVA技巧 sense.

What do you name your arrays when the name of the item is already plural?

array names makes开发者_JAVA技巧 sense. array collisionDatas not so much.


I almost always name it as Item name + s. My goal when naming a variable is to make sure that I reduce the effort needed to read and understand source code.

So if I have an array of children for example I name it childrens. I don't care at all if the childrens is an english word or not, I'm not writing a book! So later when a see something like: foreach (Object x in childrens) I know I'm iterating on an array of children and not on an array of child objects.


Your question heavily depends on the programming language. Objective-C has strong naming conventions that people adhere to.

Try collisionDataArray.

Personally, I'm used to Cocoa and Objective-C nowadays, and over here long variable and class names are not unusual. For me, autocomplete is good enough, and the code ends up being quite readable.


I sometimes add the type in front, like:

array arrNames

array arrColisionData

I prefer to add the "arr" in the beginning so when you get them in an ordered list, they stay together.

0

精彩评论

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

关注公众号