Teach me how to give a name...

This is a discussion on Teach me how to give a name... within the C Programming forums, part of the General Programming Boards category; Which do you prefer? TokenA, TokenB, TokenC or TokenD? Code: typedef struct { unsigned char *data; unsigned char type; unsigned ...

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    Unhappy Teach me how to give a name...

    Which do you prefer? TokenA, TokenB, TokenC or TokenD?

    Code:
    typedef struct
    {
        unsigned char *data;
        unsigned char type;
        unsigned int line;
        unsigned int column;
    
    } TokenA;
    
    typedef struct
    {
        unsigned char *data;
        unsigned char  type;
        unsigned int   line;
        unsigned int   column;
    
    } TokenB;
    
    typedef struct
    {
        unsigned char *data;
        unsigned char  type;
        unsigned  int  line;
        unsigned  int  column;
    
    } TokenC;
    
    typedef struct
    {
        unsigned char  *data;
        unsigned char   type;
        unsigned  int   line;
        unsigned  int column;
    
    } TokenD;
    I don't know... Maybe there is something wrong with my brain.

    When writing variables, defines, functions or typedefs I'm stuck with their name, spaces and indentation!

    ...TokenA or Token_A or tokenA or token_a or TOKEN_A... :S

    ...char *token or char *sToken or char *strToken or char *lpcstrToken...

    Could you imagine? Whenever my mood is using MyFunction style...
    I will rewrite--yeah! rewrite! the whole function named my_function, then rename it to MyFunction either in the same algorithm or a new one.

    Am I crazy? Yes I am.

    Somebody help me!! (-*_*-)"

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I prefer the TokenA style - it's natural looking and avoids obsessing over how the words of differing lengths, all line up in an affected looking manner.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Which do you prefer?
    No, the question really is which do you prefer?

    >Am I crazy?
    As long as you're consistent within the project, all is well.
    My best code is written with the delete key.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Could you imagine? Whenever my mood is using MyFunction style...
    I will rewrite--yeah! rewrite! the whole function named my_function, then rename it to MyFunction either in the same algorithm or a new one.
    Yes, this sounds sort of crazy.

    Imagine working with several 3rd party APIs, each using their own naming conventions...
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    TokenA. The rest are too much. Think of it this way. If you try to make the code nice but more impractical, then what's the point? The code isn't nice to win any beauty contest. It is nice to be practical, easy to read and easy to modify. So it should first be practical and then "nice". Though practical codes tend to be nicer anyway.

    Now, my_function vs MyFunction vs myFunction. That is a tough call.
    First, I would say not MyFunction, but myFunction. One less shift :P
    So you have my_function vs myFunction. Now depends on what YOU like.
    I would say some advantages (for ME), to give you some ideas:

    1) The words are more separate, meaning you can read them more easily. This is useful if you have two long or strange words. Even more useful when you have three words like "my_function_opt" rather than "myFunctionOpt
    2) The _ makes the word a little more "ugly". Also it is easier to use the capital letter format, because you just press a shift, not a shift plus -. So if you don't mind, use the myFunction format just because it is easier.
    3) It is better to use one format for each program

    My advise. Choose one in the beginning and STICK with it!

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Also it is easier to use the capital letter format, because you just press a shift, not a shift plus -.
    Pressing Shift alone doesn't produce an uppercase character.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  7. #7
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Very reasonable C_ntua... Great!

    Speed of typing is one of important things while writing a code..

    ...Type less get more...
    *giggle*

    Because of we, the programmers, should be lazy at all XD

  8. #8
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Lazy programmers would use auto-completion by their IDE...
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  9. #9
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by audinue View Post
    Very reasonable C_ntua... Great!

    Speed of typing is one of important things while writing a code..

    ...Type less get more...
    *giggle*

    Because of we, the programmers, should be lazy at all XD
    Personally I HATE symbols like parenthesis, underscore, brackets etc etc (I should be programming in Haskell....) :P

  10. #10
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I use TokenB syntax for member variables and something like TokenC syntax for function arguments. I think it's just easier to see the variable types & names when you're looking through the code quickly.
    I just wish I could keep my desk as neat & organized as my code.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm with cpjust on this - but coding style is a personal thing, at least until you start working with other people that have a different idea of what coding style you should use. I don't use the coding style used at work when I write code at home.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. please give ur point of view
    By clover in forum C Programming
    Replies: 2
    Last Post: 05-04-2004, 03:56 PM
  2. Give me some opinions on setting up a server
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 04-19-2004, 10:38 AM
  3. Can you give me your tip plz :)
    By dionys in forum C Programming
    Replies: 6
    Last Post: 04-11-2004, 11:14 PM
  4. How To Give A Font Colour ?
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 09-14-2001, 01:22 PM
  5. Just to give you an idea of what we're going through...
    By rick barclay in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 09-13-2001, 02:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21