PDA

View Full Version : Plural Array Names



RogerDodger
11-29-2010, 03:02 AM
Would you say that giving an array a plural name makes more sense (from a linguistics stand point) than a singular one?

For example, if I have a list of colours, red, blue, green and yellow, would naming an array containing them @colours or @colour be more acceptable?

The plural form makes more sense when defining the array, as:

@colours = ("red","blue","green","yellow");

However, when calling the array having the singular form makes more sense:

print "My favourite colour is $colour[1]";

What say you OT?

INEED2BUKKS
11-29-2010, 04:15 AM
Singular is better

Sauron`
11-29-2010, 04:16 AM
As I said in the other thread, I use anXXXXlist to define my arrays.

the word list always defines it as a "List" of N type that is an array (a) so it seems to be pretty clear to the person reading my code.

Not saying it's the best way, but it's just how I do it. I think when you call an array such as aNPersonList[1] people will understand that you are taking the second person from the array of PersonList (since people that are reading your code when have at least a basic programming background....or at least they should) your customer will 99999999999999999% of the time not be reading your code.

RogerDodger
11-29-2010, 04:39 AM
There's no point of suffixing your arrays with 'List' when by virtue of arrays being lists the context clearly implies that you're working with a list.

I like my code to read as close to English as possible, I've found that generally using a plural term makes more sense as the call of a plural can be read as "Take the 2nd value from the list of colours", whereas stating a list in the singular sense is really quite awkward.

Sauron`
11-29-2010, 05:08 AM
Im just saying thats how I do it in my job, and people have never Not understood what I was saying.
When you start having tons of local variables and pointers flying everywhere. having the word LIST in the variable name really helps. So yes there is a point actually, and most interview questions will ask about naming conventions regarding arrays. And generally you want to include List/Array in the variable name.

RogerDodger
11-29-2010, 05:13 AM
The $ and the index being in square brackets already 100% verifies by context that the thing being called is an array. I can't think of any reason a convention would be in place to consistently force the addition of 4 characters to every list you type.

Also, using it in that context reads very poorly when being called, and barely reasonable when being defined.

Sauron`
11-29-2010, 05:26 AM
The $ and the index being in square brackets already 100% verifies by context that the thing being called is an array. I can't think of any reason a convention would be in place to consistently force the addition of 4 characters to every list you type.

Also, using it in that context reads very poorly when being called, and barely reasonable when being defined.

Not in all languages, and Im just telling you the naming convention standards. Verifying by context isn't enough when you have thousands upon thousands of lines of code. You want it to be as clear and concise as possible. Which is why people either choose plural names, or append List at the end. Especially if it's in C code.

I suggest you look at this SA thread
http://stackoverflow.com/questions/395739/do-you-name-your-arrays-plurally-or-singularly

Obviously people differ, but it tends to lean more towards plural if you wanted a direct answer.

RogerDodger
11-29-2010, 05:42 AM
Thanks for that link, has a lot of good opinons and arguments :].

Kowz
11-29-2010, 09:47 AM
http://i205.photobucket.com/albums/bb155/kowzz/1280403719935.gif

YawningAngel
11-29-2010, 12:25 PM
Obviously, the solution is to only name arrays such that singular and plural are indistinguishable, e.g. @fish and @sheep.

Zasus
11-29-2010, 12:51 PM
what yawning wrote