Naming Convention(s)

R

Roedy Green

People usually feel very passionately about matters such as this one.
I have not seen any official pronouncement on it:

Do you prefer singular or plural names for:
1. arrays
2. collections
3. directories

In other words do you prefer goats or goat, HashSet goats or
HashSet goat, the C:\goats directory or the C:\goat directory.

By the way, what brought this on was the discovery that I can't have
an icons directory on my website since Apache reserves that name for
its own purposes. I had to rename to the icon directory.


for ( goat : goats ) is an argument for plural names.
 
A

Andrew Thompson

In other words do you prefer goats or goat, HashSet goats or
HashSet goat, the C:\goats directory or the C:\goat directory.


I prefer ..

// slightly tongue in cheek..
HashSet goatHerd;
 
S

Skip

Roedy Green said:
People usually feel very passionately about matters such as this one.
I have not seen any official pronouncement on it:

Do you prefer singular or plural names for:
1. arrays
2. collections
3. directories

In other words do you prefer goats or goat, HashSet goats or
HashSet goat, the C:\goats directory or the C:\goat directory.


I, for one, stick to this:

Goat[] goat = ...;
Collection goats = ...;

Because
goat[x].getParent();
feels like: "goat X -> get parent", and
goats.get(x).getParent();
feels like: "out of all goats, pick X -> get parent"

goats[x] feels very unnatural IMHO.

Besides that, whenever it's "goats", I know it's a collection
(list,map,set).
 
J

jan V

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.
 
S

Skip

jan V 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.
 
T

Tjerk Wolterink

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();


Ok were dealing with an array of goats
// pronounce "goats at i = new goat"

// B
goat = new Goat();


Ok were dealing with a array that represents a goat.
// pronounce "goat at i = new goat"


What if i want to represent a goat with an array?
Then you have a problem.

For example

Object[] goat={
new GoatSound(),
new GoatTeeth()
}


??

So use the plural form to be sure your dealing with an array of goats.
 
S

Skip

Tjerk Wolterink said:
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();


Ok were dealing with an array of goats
// pronounce "goats at i = new goat"

// B
goat = new Goat();


Ok were dealing with a array that represents a goat.
// pronounce "goat at i = new goat"


What if i want to represent a goat with an array?
Then you have a problem.

For example

Object[] goat={
new GoatSound(),
new GoatTeeth()
}


??

So use the plural form to be sure your dealing with an array of goats.


While I see your point, I think representing a goat with an array is poor
design.
 
T

Thomas Hawtin

Roedy said:
People usually feel very passionately about matters such as this one.
I have not seen any official pronouncement on it:

Do you prefer singular or plural names for:
1. arrays
2. collections
3. directories

Plural. Sets are potentially obscure enough to have a "Set" suffix.
"Map" suffix for a map.

Singular for SQL tables and packages. With SQL you are refer to tables
when in fact you are just after individual rows (if you see what I
mean). java[x].* packages are inconsistently names, but you don't give
class plural names, in general.

Tom Hawtin
 
H

Hemal Pandya

Roedy said:
People usually feel very passionately about matters such as this one.
I have not seen any official pronouncement on it:

Do you prefer singular or plural names for:
1. arrays
2. collections
3. directories

In other words do you prefer goats or goat, HashSet goats or
HashSet goat, the C:\goats directory or the C:\goat directory.


I personally like plural form. I have even come across the goatS style,
with capital S.

I have a follow-up question. If you do prefer the plural form, what do
pluralize nouns that have irregular plural forms in English? wolfs or
wolves? geese or gooses? deers or deer?
 
A

Andrew Thompson

Roedy Green wrote: ...
In other words do you prefer goats or goat, HashSet goats or
HashSet goat, the C:\goats directory or the C:\goat directory.
...
I have a follow-up question. If you do prefer the plural form, what do
pluralize nouns that have irregular plural forms in English? wolfs or
wolves?
pack.

..geese or gooses?
flock.

..deers or deer?


herd.

;-)
 
T

Tjerk Wolterink

Skip said:
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();


Ok were dealing with an array of goats

// pronounce "goats at i = new goat"

// B
goat = new Goat();


Ok were dealing with a array that represents a goat.

// pronounce "goat at i = new goat"


What if i want to represent a goat with an array?
Then you have a problem.

For example

Object[] goat={
new GoatSound(),
new GoatTeeth()
}


??

So use the plural form to be sure your dealing with an array of goats.



While I see your point, I think representing a goat with an array is poor
design.


Yes, but sometimes (not to often) you use a array to represent
a single thing. Sometimes it is good design (if
speed and low memory usage are requirements).

So if you use the plural form you avoid these problems.

But off course its your choice.
 
A

Andrew Thompson

And before the generics were born, when you removed an element from it,
how did you know if its a goat or a deer?

D'Oh! My bad.

OK - how about..
packOfWolves,
flockOfGeese, (flockOfSeagulls, murderOfCrows)..
herdOfDeer (herdOfGoats)...
To you too ;-)

LOL!
 
I

iamfractal

I wouldn't have thought a, "Set," suffix is good; anywhere I need a Set
I use a Collection.

As for Maps, I tend to use xToY notation: nameToEmployee,
productToPrice, etc.

..ed
 
W

Wibble

Andrew said:
D'Oh! My bad.

OK - how about..
packOfWolves,
flockOfGeese, (flockOfSeagulls, murderOfCrows)..
herdOfDeer (herdOfGoats)...




LOL!
The hardest choices to make are the ones where the
outcome makes the least difference.
 
R

Roedy Green

Ok were dealing with an array of goats

In natural English goats means a group of goats in the aggregate. goat
represents a single goat.

Goat[] goats; then represents the entire set of goats.

So I suppose in some more natural language you might say

goats = new Goat[ 10 ];

but

goat = new Goat();

I further suppose in this natural language,

for ( Goat goat : goats )

would sound silly, and would be abbreviated:

for each goat
 
R

Roedy Green

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.

At some point I can see the [] syntax being extended to work with all
Maps or at least Lists. Whatever convention you adopt should survive
that.
 
R

Roedy Green

for ( Goat goat : goats )

Java is unlike English in that it has no standard spoken form.

Programs have quite different meaning when word capitalisation, both
initial and middle, changes.

In FORTH, there were official pronunciations for all the command
words, e.g. ' is called tick, DUP is called dupe, ROT is called rote,
Like Java , Forth is case sensitive.

I assume in the absence of an official way of pronouncing Java, people
have cooked up their own ad hoc schemes they use for telephone Java.

Or perhaps people never try to exchange literal code without spelling
it out letter by letter, but rather use pseudocode, e.g. Sort the
goats by beard length.
 
R

Roedy Green

but you don't give
class plural names, in general.

Usually the class represents the information about a single goat, not
the collection of goats, so that makes sense.
 
C

Chris Smith

Roedy Green said:
People usually feel very passionately about matters such as this one.
I have not seen any official pronouncement on it:

Do you prefer singular or plural names for:
1. arrays
2. collections
3. directories

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.

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.

Odd as it may sound, I think that property is a critical check on choice
of style. Stylistic concerns such as identifier naming affect our
programming in all sorts of ways, and it's actually quite likely that
someone will eventually end up obscuring code or even misdesigning an
API with horrifying complexity just because it didn't occur to them to
pass "goat" as a parameter... even if passing "goats" would have made
perfect sense.

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.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top