Naming Convention(s)

Discussion in 'Java' started by Roedy Green, Sep 3, 2005.

  1. Roedy Green

    Roedy Green Guest

    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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 3, 2005
    #1
    1. Advertising

  2. On Sat, 03 Sep 2005 08:44:00 GMT, 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 prefer ..

    // slightly tongue in cheek..
    HashSet goatHerd;

    --
    Andrew Thompson
    physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
    "Your eyes, no surprise, are open wide.."
    Divinyls 'Good Die Young'
     
    Andrew Thompson, Sep 3, 2005
    #2
    1. Advertising

  3. Roedy Green

    Skip Guest

    "Roedy Green" <> wrote in message
    news:...
    > 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).

    >
    > 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.
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Again taking new Java programming contracts.
     
    Skip, Sep 3, 2005
    #3
  4. Roedy Green

    jan V Guest

    > 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.
     
    jan V, Sep 3, 2005
    #4
  5. Roedy Green

    Skip Guest

    "jan V" <> wrote in message
    news:OKdSe.184918$-ops.be...
    > > 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.
     
    Skip, Sep 3, 2005
    #5
  6. Skip wrote:
    > "jan V" <> wrote in message
    > news:OKdSe.184918$-ops.be...
    >
    >>>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.
     
    Tjerk Wolterink, Sep 3, 2005
    #6
  7. Roedy Green

    Skip Guest

    "Tjerk Wolterink" <> wrote in message
    news:dfbsen$841$...
    > Skip wrote:
    > > "jan V" <> wrote in message
    > > news:OKdSe.184918$-ops.be...
    > >
    > >>>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.
     
    Skip, Sep 3, 2005
    #7
  8. Roedy Green wrote:
    > 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
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
     
    Thomas Hawtin, Sep 3, 2005
    #8
  9. Roedy Green

    Hemal Pandya Guest

    Roedy Green wrote:
    > 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?
     
    Hemal Pandya, Sep 3, 2005
    #9
  10. On 3 Sep 2005 03:51:12 -0700, Hemal Pandya wrote:
    > 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.

    ;-)

    --
    Andrew Thompson
    physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
    "Tell 'em a hooka smokin' caterpillar, has given you the call.."
    Jefferson Airplane 'White Rabbit'
     
    Andrew Thompson, Sep 3, 2005
    #10
  11. Skip wrote:
    > "Tjerk Wolterink" <> wrote in message
    > news:dfbsen$841$...
    >
    >>Skip wrote:
    >>
    >>>"jan V" <> wrote in message
    >>>news:OKdSe.184918$-ops.be...
    >>>
    >>>
    >>>>>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.
     
    Tjerk Wolterink, Sep 3, 2005
    #11
  12. Roedy Green

    Hemal Pandya Guest

    Andrew Thompson wrote:
    > >..deers or deer?

    >
    > herd.

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

    >
    > ;-)

    To you too ;-)
     
    Hemal Pandya, Sep 3, 2005
    #12
  13. On 3 Sep 2005 05:45:03 -0700, Hemal Pandya wrote:

    > Andrew Thompson wrote:
    >>>..deers or deer?

    >>
    >> herd.

    > 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!

    --
    Andrew Thompson
    physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
    "..because you're mine."
    Screamin' Jay Hawkins 'I Put A Spell On You'
     
    Andrew Thompson, Sep 3, 2005
    #13
  14. Roedy Green

    Guest

    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

    --
    www.EdmundKirwan.com - Home of The Fractal Class Composition
     
    , Sep 3, 2005
    #14
  15. Roedy Green

    Wibble Guest

    Andrew Thompson wrote:
    > On 3 Sep 2005 05:45:03 -0700, Hemal Pandya wrote:
    >
    >
    >>Andrew Thompson wrote:
    >>
    >>>>..deers or deer?
    >>>
    >>>herd.

    >>
    >>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!
    >

    The hardest choices to make are the ones where the
    outcome makes the least difference.
     
    Wibble, Sep 3, 2005
    #15
  16. Roedy Green

    Roedy Green Guest

    On Sat, 03 Sep 2005 12:04:10 +0200, Tjerk Wolterink
    <> wrote or quoted :

    >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

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 3, 2005
    #16
  17. Roedy Green

    Roedy Green Guest

    On Sat, 03 Sep 2005 09:09:02 GMT, "jan V" <> wrote or quoted
    :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 3, 2005
    #17
  18. Roedy Green

    Roedy Green Guest

    On Sat, 03 Sep 2005 20:41:59 GMT, Roedy Green
    <> wrote or quoted :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 3, 2005
    #18
  19. Roedy Green

    Roedy Green Guest

    On Sat, 03 Sep 2005 11:30:14 +0100, Thomas Hawtin
    <> wrote or quoted :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 3, 2005
    #19
  20. Roedy Green

    Chris Smith Guest

    Roedy Green <> wrote:
    > 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
     
    Chris Smith, Sep 3, 2005
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick

    Which c# naming convention?

    Rick, Jan 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,850
    Paul Glavich
    Jan 19, 2004
  2. dm1608
    Replies:
    6
    Views:
    8,629
  3. Buck Turgidson

    JSP Method Naming Convention

    Buck Turgidson, Mar 2, 2004, in forum: Java
    Replies:
    1
    Views:
    1,793
    P.Hill
    Mar 2, 2004
  4. harry
    Replies:
    2
    Views:
    1,238
    harry
    Dec 8, 2004
  5. Unpredictable

    Variable naming convention

    Unpredictable, Jan 3, 2006, in forum: Java
    Replies:
    4
    Views:
    557
    Roedy Green
    Jan 3, 2006
Loading...

Share This Page