Thread: building a tree - The Off Topic Babble

  1. #1
    Registered User fischerandom's Avatar
    Join Date
    Aug 2005
    Location
    Stockholm
    Posts
    71
    What Salem just wrote above is very common, I see it so often but I think it is an illogical array- or vector-naming scheme. Why do some people, even experienced programmers, use:
    Code:
    typedef struct Node {
        struct Node*     branches[ 9 ];
        /* other members. . .*/
    } Node;
    rather than. . .
    Code:
    typedef struct Node {
        #define BRANCHES    9
        struct Node*     branch[ BRANCHES ];
        /* other members. . .*/
    } Node;
    I think the confusion, when naming the array, is that they are thinking about that there is several items in the array and hence they name it, for example, branches[ BRANCHES ] rather than branch[ BRANCHES ]. What do you guys feel is right? Accessing a node with node.branch[ n ] or node.branches[ n ]? What looks best, feels best, is most logical?
    Last edited by fischerandom; 01-01-2006 at 11:46 AM.
    Bobby Fischer Live Radio Interviews http://home.att.ne.jp/moon/fischer/

  2. #2
    Registered User fischerandom's Avatar
    Join Date
    Aug 2005
    Location
    Stockholm
    Posts
    71
    Salem often use the plural form when declaring arrays of things, if that makes the code more readable.

    In what way does it make the code "more readable"? When declaring the name of an array or vector, etc., the access of an element in the array/vector is that of a single object, so the singular-form is logical!!! When declaring the array/vector, it is very clear there is [ OBJECTS ] in the array and we access object[ n ], not objects[ n ].

    #define OBJECTS in the struct is also suitable, the scope is not limited to that struct, but OBJECTS belongs to the struct (is used in conjunction with defining the array size, etc.) If that style (typically putting a define size of array size in the struct as close as possible to the array) works in the Darwin kernel code in MacOS X, then it works for me too.
    Bobby Fischer Live Radio Interviews http://home.att.ne.jp/moon/fischer/

  3. #3
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    I suppose it is just a matter of personal preference.

    Personally, I don't pay much attention to the grammar of the variable names I select. If they describe what I'm declaring accurately in reference to the big picture, if other programmers can understand what I'm doing, if it is well commented, and (most importantly) if it runs and is done on time and in budget, then I don't worry if it is singular or plural.

    But again, that's just my personal preference....

    Quote Originally Posted by fischerandom
    Salem often use the plural form when declaring arrays of things, if that makes the code more readable.

    In what way does it make the code "more readable"? When declaring the name of an array or vector, etc., the access of an element in the array/vector is that of a single object, so the singular-form is logical!!! When declaring the array/vector, it is very clear there is [ OBJECTS ] in the array and we access object[ n ], not objects[ n ].

    #define OBJECTS in the struct is also suitable, the scope is not limited to that struct, but OBJECTS belongs to the struct (is used in conjunction with defining the array size, etc.) If that style (typically putting a define size of array size in the struct as close as possible to the array) works in the Darwin kernel code in MacOS X, then it works for me too.

  4. #4
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    >Every thread is not about debating what everyone else does in every instance of programming.
    This really isn't the place for my own observations, but from what I've seen, it seems like there's a huge amount of arrogance on these forums. Not the "I'm holier than thou" attitude that you usually equate with arrogance, but subtle stuff, like a nit-picky correction or addition that only serves to make someone look more right than the person they're responding to. It's pretty funny to watch the chains of one-upping if you're looking for it.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660

  6. #6
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    Quote Originally Posted by Slacker
    >Every thread is not about debating what everyone else does in every instance of programming.
    This really isn't the place for my own observations, but from what I've seen, it seems like there's a huge amount of arrogance on these forums. Not the "I'm holier than thou" attitude that you usually equate with arrogance, but subtle stuff, like a nit-picky correction or addition that only serves to make someone look more right than the person they're responding to. It's pretty funny to watch the chains of one-upping if you're looking for it.

    Good point, Slacker. I've run into this in the workplace as well. In fact, sometimes it almost sinks to the point of discussing religions and politics -- someone thinks they are right, or "more right", or "better", and no matter how long you discuss it, people's minds probably are not going to change....

  7. #7
    Registered User fischerandom's Avatar
    Join Date
    Aug 2005
    Location
    Stockholm
    Posts
    71
    The greatest flaw in humans! They can't confess they're wrong even when they know they're wrong!

    On the chessboard lies and hypocrisy do not survive long. The creative combination lays bare the presumption of a lie; the merciless fact, culminating in a checkmate, contradicts the hypocrite. - EMANUEL LASKER

    Being a chess player myself, and being raised the way I was, I am unable to lie.
    Bobby Fischer Live Radio Interviews http://home.att.ne.jp/moon/fischer/

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    WTF are you talking about?

  9. #9
    Registered User fischerandom's Avatar
    Join Date
    Aug 2005
    Location
    Stockholm
    Posts
    71
    OK, I am talking about why some people, even experienced programmers, prefers a plural naming scheme of arrays/vectors instead of a singular naming scheme. I simply wonder why! I use the singular form because you always access a single object in the array. Look how stupid it looks when you say: apples[ i ].color = RED compared to apple[ i ].color = GREEN.

    Singular array/vector naming scheme:
    Code:
    typedef struct Apple {
        #define GREEN    1
        #define YELLOW  2
        #define RED         3
        int     color;
    } Apple;
    
    int     main( ) {
        #define APPLES    64
        Apple   apple[ APPLES ];    /* Singular array/vector naming scheme, because. . . */
        int        i;
        
        for ( i = 0; i < APPLES; ++i )
            apple[ i ].color = GREEN;    /* . . .the access is of a single object! */
        
        return 0;
    }
    Plural array/vector naming scheme:
    Code:
    typedef struct Apple {
        #define GREEN    1
        #define YELLOW  2
        #define RED         3
        int     color;
    } Apple;
    
    int     main( ) {
        #define APPLES    64
        Apple   apples[ APPLES ];    /* Plural array/vector naming scheme, because?  */
        int        i;
        
        for ( i = 0; i < APPLES; ++i )
            apples[ i ].color = RED;    /* . . .yes that is my question. Why? */
        
        return 0;
    }
    Last edited by fischerandom; 01-04-2006 at 05:59 AM.
    Bobby Fischer Live Radio Interviews http://home.att.ne.jp/moon/fischer/

  10. #10
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    This has to be a joke. I guess thats why it makes me laugh.

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Being raised the way [fischerandom] was, [fischerandom is] unable to joke.

    What this thread really boils down to is fischerandom feeling threatened, because the long time posters have for the most part just ignored [fischerandom]'s attempts at wowing them with [fischerandom]'s "mad skillz", and so it's another attempt to prove that they do in fact have a penis, and that it's really really big. Honest. Because [fischerandom] cannot tell a lie! They're a regular George Washington! Oh, and they've got "mad skillz"! And a big penis. Honest Abe! Honest Injun! Honest!! Really! You've got to believe them!


    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    We should bring back back rep points.

  13. #13
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I'm a little rusty so hopefully he'll be able to help me with this
    Code:
    typedef struct Ban {
        #define USER "fischerandom"
        #define HOWLONG  3
        #define UNITS DAYS
        #define WHY  "Because I can"
        int     activated;
    } Ban;
    int     main( ) {
      Ban HeresHopingHeWontComeBack;
      HeresHopingHeWontComeBack.activated=1;
      return 0;
    }

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > prefers a plural naming scheme of arrays/vectors instead of a singular naming scheme.
    plurals on #define names - good, because I'm the #define god.
    plurals on array names - bad, because I didn't think of that first, It's a good idea, I just can't admit it to myself.

    It must be a new record. Just 3 threads started by fischerandom, those other two got closed due to flames and this one resulted in a ban.

  15. #15
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Plural? Singular?

    An array is merely a function with a contiguous subset of the integers as its domain, and goofy syntax. Just like the factorial function. We don't say "factorials i", do we? We don't say "factorial i", either. We say "i factorial". (There is also a related function, the "do not factorial" function.)

    Inspired by this most rational of functions, the factorial, all arrays shall now be referenced with the array name positioned after the integer. For many of you, this means much more debugging. For me, much much less.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 09:09 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM