Thread: Formatting Standards

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367

    Question Formatting Standards

    Is it me or am I just arrogant? One of the most annoying things I come across is the way in which people code differently, i.e. formatting. It is really iterating when you see code indented by about 40 tab spaces between curly braces, and your scrolling across the screen for about a mile. I personally think there should be a formatting standard, and not just a guideline. Anybody agree on this?
    Be a leader and not a follower.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Re: Formatting Standards

    Originally posted by subdene
    It is really iterating when you see code indented by about 40 tab spaces between curly braces,


    It's not that easy to do as it may sound.

    And if there will be a global style, it better not be the kernel. I hate it . It's so damn ugly when the preceeding bracket is placed last on the previous line...

    ...perhaps I'm a little pedantic...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    well i just wish people could follow guidelines. That way reading and maintaining code could would be that much easier.
    Be a leader and not a follower.

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    i hate curly's on same ligns, example:

    Code:
    for (int i = 1; i >=100; ++i){
    
    cout<<i<<endl;}
    
    as opposed to
    
    for (int i = 1; i >=100; ++i)
    {
    
    cout<<i<<endl;
    
    }

  5. #5
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Well none of the majors use a closing brace after a semicolon, that'd be just wrong.

    I use the K&R (also called kernel or 1TBS), where opening braces are places on the same line as whatever flow control structure te braces are used to denote.

    The other major style is Allman, in which the opening curly braces are on the next line down. This style is for people who are stylistically defective.

    There is actually another division of each of these, that is the placement of the closing curly brace on either the enclosed or enclosing scope. The enclosing scope is largely prefered, and used almost exclusively by kernel style coders, while Allman sometimes uses the enclosed, again attributable to defects in the users of this brace style.

  6. #6
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    yes, i use the "allman" style, just how i've taught.
    Be a leader and not a follower.

  7. #7
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198
    I have always like to put opening and closing curly braces on a line by themselves, since I can locate the faster and check for unbalanced braces at the same time. I guess people just code using their own personal preference.
    -MethodMan-

    Your Move:Life is a game, Play it; Life is a challenge, Meet it; Life is an opportunity, capture it.

    Homepage: http://www.freewebs.com/andy_moog/home.html

  8. #8
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    i agree with method man
    I use the almann style simply because it's easier to find chunks of code and to identify missing brackets (unexpected eof found). I used to do the other way
    function(){
    whatever;
    }
    but i like this way better

    imperito,
    so why exactly am i defective?
    PHP and XML
    Let's talk about SAX

  9. #9
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    I have to say that I hate K&R style and definately prefer Allman. This is because I find it make the code much more readable. Also very easy to spot missing braces and brackets. About the only time I change this is maybe an empty constructor body.... just {} after the initialization list and on simple accessor functions where it helps to just bang it all on the one line. Helps group related functions together without bags of whitespace between them.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  10. #10
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Cool

    As an instructor I force my students to follow coding standards.
    I prefer the Allman way. However, I make my Java students follow the Java programming conventions set by Sun.
    Mr. C: Author and Instructor

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    I had a URL that I can no longer find. On it were a list of university and business studies of C/C++ coding formats. In all the studies, Allman formatting came out with the best readability and lowest error stats.

    The old fashioned K+R type formats, (there are acouple of others - Stroustrup, Whitesmith, etc.), are less readable. The original formatting was created because the printers of the day, (remember, people used to print out their code and plan their edits before returning to the card punch of teletype!), used less paper because the code læength was that little bit shorter.

    With a modern scrolling full file editor/IDE this is no longer an issue.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    I personally think there should be a formatting standard, and not just a guideline. Anybody agree on this?
    All companies I know have coding standards which include formatting.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  13. #13
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    Originally posted by nvoigt
    All companies I know have coding standards which include formatting.
    Not mine. They just want whatever works in the shortest amount of time. Not good, I know. Try maintaining 50K+ line programs written in a variety of styles with no comments at all.
    Truth is a malleable commodity - Dick Cheney

  14. #14
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Allman style here.

    But since I cut and paste a lot of code from tutorials because I am still in "complete newbie" mode, my code ends up very messed up. Allman style here, kernel style there, hungarian notiation here, etc.

  15. #15
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    This just about sums up my thoughts on hungarian notation.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question - linux - gcc - c standards
    By AMAMH in forum C Programming
    Replies: 12
    Last Post: 12-03-2009, 02:49 AM
  2. Code Standards
    By WP99 in forum C Programming
    Replies: 2
    Last Post: 08-31-2007, 04:43 PM
  3. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM
  4. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM
  5. Keeping up with newest standards
    By Shadow12345 in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2002, 08:06 AM