Naming Convention(s)

R

Roedy Green

nouns that have irregular plural forms in English? wolfs or

pack.

There is a book called An Exaltation of Larks, the Art of Venery on
the topic. Knights used to haze their squires by requiring them to
memorise all manner of group names, and laughing at those who made an
error.

If you are interested is seeing my collection and a link to the book
see: http://mindprod.com/jgloss/collectivenouns.html
 
R

Roedy Green

Incidentally, after a few months of common use, the plural form with
array indexing doesn't seem so odd any more. To underscore the point,
it actually reminds you of what's going on -- that you're starting with
a collection and selecting a single element -- instead of glossing over
the details and obscuring the underlying memory model.

musings on goats

Which makes one sense depends on how you think it/speak it to
yourself:


the ith goat

select the ith from goats

array goats, element i.

current goat

the goat

a goat

next goat

pick from goats

efficient collection goats, get i;


to me goats is a quite different syntactic animal from goats[j]. i
is for rigidly standard loops. Anything else is for fancy stuff. In my
own language Abundance the two are visually distinct. There is an
implied subscript inside loops.
 
C

Chris Uppal

jan said:
goats[x] feels very unnatural IMHO.

It will never cease to amaze me how any two intelligent people can use
rational thought to arrive at completely opposite conclusions.

Nor me.

goats[x] feels the only right choice to me, with goat[x] being the
approach I cringe at. Whether it's a primitive array or a Collection, the
two are logically equivalent, so the use of plural applies to both.

That's the way I would see it too, /unless/ the array of goats was thought of
as just an implementation technique for the situation where what you /really/
want is variables named:

Goat goat1 = //....
Goat goat2 = //....
Goat goat2 = //....
...
Goat goatN = //....

and the array itself is never seen as an object, or collection, in its own
right.

I admit that I can't remember every having to write such code, though. But,
OTOH, I find the following equally cringe-making:

eum Colours
{
Red,
Blue,
Green
}

the enum should be named "Colour" since that is the name of the type of which
each of Red, Green, and Blue are instances.

A similar sort of reasoning but applied in the opposite direction...

-- chris
 
J

John C. Bollinger

Skip said:
goats[x] feels very unnatural IMHO.

It will never cease to amaze me how any two intelligent people can use
rational thought to arrive at completely opposite conclusions.

goats[x] feels the only right choice to me, with goat[x] being the
approach

I cringe at. Whether it's a primitive array or a Collection, the two are
logically equivalent, so the use of plural applies to both.


for(int i=0; i<n; i++)
{
// A
goats = new Goat();
// pronounce "goats at i = new goat"

// B
goat = new Goat();
// pronounce "goat at i = new goat"

// C
goats.set(i, new Goat());
// pronounce "set new goat at i, in goats"
}

That would be my "rational thought", which I realize from another POV is
easily breakable. Matter of taste I think.


I also prefer the plural form for arrays, but it comes more from the
fact that the thing I am naming is the aggregate rather than from any
consideration of access to individual members. This may be related to
an acute awareness of arrays as objects in their own right. For an
alternative argument based on how a piece of code reads, which of these
do you think reads more intelligibly:

Animal[] goat = new Animal[100];
// ... initialize
feedAnimals(goat)

OR

Animal[] goats = new Animal[100];
// ... initialize
feedAnimals(goats)

Personally, I'll go for the latter every time.
 
D

Dale King

Chris said:
As someone who is exactly anal retentive enough to care about this... I
started out many years ago using singular forms for arrays, and plurals
for the remainder. I did it for exactly the same reason someone else
mentioned: the array access syntax "sounded" better. After about six
months of serious work, I realized that this was ridiculous, and
switched.

I think arrays are the only one that there seems to be a disagreement.
The concensus seems to be that for collections you either use plural or
a word that describes a group (e.g. goatHerd).
IMO, the best argument for switching is that arrays aren't ALWAYS used
for indexing. Sometimes array references are passed around in their own
right. For example, I may pass an entire array reference to a method.
In that case, it's incredibly awkward and inexplicable to use "goat"
instead of "goats". I eventually realized that my naming conventions
were catering to a limited subset of the language and lacked the
essential property of closure over the entire language.

I agree with your reasoning but come to a different conclusion. I agree
is is awkward to use the singular when you deal with the group as a
whole. But it is also awkward to use the plural when indexing. That is
why I don't believe the choice for arrays is an either or. I think the
choice on which to use depends on the array and how it is used. I will
use the singular form when primarily using array indexing, but use
plural when the array is referred to as a whole for a significant amount.

So I agree that using the singular is catering to a limited subset of
the language, but if that is where the array is primarily used then I
follow that convention.

But as someone pointed out the use of array indexing is much less with
foreach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top