View Poll Results: Where do you put your opening brace?

Voters
53. You may not vote on this poll
  • Style 1 (opening brace on same line)

    18 33.96%
  • Style 2 (opening brace on next line)

    35 66.04%

Curly Brace Placement

This is a discussion on Curly Brace Placement within the General Discussions forums, part of the Community Boards category; I use #2, but I'm thinking of switching to this format to ........ off all the #1 people Code: void ...

  1. #16
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I use #2, but I'm thinking of switching to this format to ........ off all the #1 people
    Code:
    void func()
                        {
    blah, blah...
                                 }
    Edit: OMG! I can't believe the word filters blanked out the 'urinate' with a 'p' word! Who came up with this filter?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  2. #17
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Style 2.

    Style 2 is also standard at work. Makes the code easier to read.

  3. #18
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Do we not know the names of these styles? Break down:
    K&R
    Code:
    int function()
    {
        if(blah) {
            code;
        } else {
            more code;
        }
    }
    • Takes up less space.
    • Orginiated from K&R and other early C advocates.


    Allman
    Code:
    int function()
    {
        if(blah)
        {
            code;
        }
        else
        {
            more code;
        }
    }
    • Braces visually line up. Some editors will even connect them with a visible line.
    • Indented blocks are clearer and higher-visibility.
    • Consistent with scheme used for functions.


    GNU
    Code:
    int
    function()
    {
        if(blah)
          {
            code;
          }
        else
          {
            more code;
          }
    }
    • Heck if I know.


    I love Allman, myself. K&R causes the code to become bunched and harder to read, IMHO. Vertical space is not an issue with todays machines as it was back in the age of dinosaurs. Additionally, people need to grow a spine and learn where their tab key is. 3-7 bytes less, and a heck of a lot easier to work with.

    Additionally, the K&R-ers and the Allman-ers should grab their pitchforks & torches, and go after the GNU-ers.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #19
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by Cactus_Hugger View Post
    GNU
    Code:
    int
    function()
    {
        if(blah)
          {
            code;
          }
        else
          {
            more code;
          }
    }
    don't forget the Whitesmiths style
    Code:
    function()
      {
      if(blah)
        { 
        code;
        } 
      else
        {
        code;
        }
      }
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  5. #20
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    I thought _that_ was GNU. Anyway, I think #1 is more compact. It will get difficult to constantly scroll up or down with style #2 (Unless you're using vim, which I don't).

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    Allman style is my favorite simply because it's easier to read and it looks more visually appealing to me.
    GNU and Whitesmiths are hated styles >_<
    And as for style #1, I don't resent it, but I don't really like it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by Cactus_Hugger View Post
    K&R causes the code to become bunched and harder to read, IMHO. Vertical space is not an issue with todays machines as it was back in the age of dinosaurs.
    Hey, I resemble that remark :-) And vertical space can still be an issue if you use a typical real-estate hogging IDE, your edit window scrunched by multiple toolbars and explorer panes. Another reason why GVim + make + bash is the ultimate IDE. ;-)

    Additionally, the K&R-ers and the Allman-ers should grab their pitchforks & torches, and go after the GNU-ers.
    I'll boil the oil...

  8. #23
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Cactus_Hugger View Post
    -Indented blocks are clearer and higher-visibility.
    If you mostly code that way yourself, I suppose this is true. As someone who (excusively) uses a K&Rish style, I honestly find the allman harder to scan.

    I love Allman, myself. K&R causes the code to become bunched and harder to read, IMHO. Vertical space is not an issue with todays machines as it was back in the age of dinosaurs.
    Only if you want to use little tiny fonts. And I would say because of widescreen monitors, it's the *horizontal* space that has increased the most drastically, eg. the view in my editor is 40x125.

    I have no issue with this, actually:
    Code:
    void somefun(int *x) { if (*x%2) *x++;  else *x+=2; }
    or anything else that will fit tidily on one line. And I sometimes put braces on the same line as an instruction inside the block *and* double up if it's something nested like this:
    Code:
    if (condition) { switch (var) {
          case;
          case;
          default; }  }
    Which allmanized would be almost *twice* as many lines. IMO C programmers may be more anal about this than programmers in other languages.
    Last edited by MK27; 05-23-2009 at 09:34 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #24
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by MK27 View Post
    And I sometimes put braces on the same line as an instruction inside the block *and* double up if it's something nested like this:
    Code:
    if (condition) { switch (var) {
          case;
          case;
          default; }  }
    Which allmanized would be almost *twice* as many lines. IMO C programmers may be more anal about this than programmers in other languages.
    Woah. Can we add a new style to this poll: MK27?
    That is... disgusting :P.
    No, sorry: that looks disgusting.

    No offence though

  10. #25
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by EVOEx View Post
    Woah. Can we add a new style to this poll: MK27?
    I'd vote for it

    Clearly you have been brainwashed, like that South Park episode where the kid gets a shock for cursing. To me it's WAY WAY better than:
    Code:
    if (condition) 
    { 
            switch (var) 
            {
                case;
                case;
                default; 
             }   
    }
    which I would consider symptomatic of brain death. You've replaced your mind with whitespace. I actually believe that people who predominantly use certian unnamed OS's, where a CLI seems like an abomination, have paid with diminished "reading comprehension" skills. Seriously.
    Last edited by MK27; 05-23-2009 at 03:12 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  11. #26
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    It also took me a lot less time to read the Allman (or for that matter, the K&R) style version instead of the MK27...

    Quote Originally Posted by MK27
    I actually believe that people who predominantly use certian unnamed OS's, where a CLI seems like an abomination, have paid with diminished "reading comprehension" skills.
    Huh? I've seen just as much K&R and Allman in Linux as I have in Windows... I can't really tie one to the other, other than perhaps the fact that MSVS for C# enforces a crappy version of Allman.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  12. #27
    Registered User
    Join Date
    Sep 2004
    Posts
    123
    Just as horrible is this, a bit like the GNU one but worse, which I've seen from time to time:

    Code:
    void foo(int i)
    	{
    	code;
    	if (a == b)
    		{
    		code;
    		}
    	}

    Fingers down the throat job.
    I think you can put a signature here.

  13. #28
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Driver View Post
    Just as horrible is this, a bit like the GNU one but worse, which I've seen from time to time:
    Yes, and in case anyone hadn't noticed, these abominations are all descended from the allmanic obscenity of not placing the opening brace on the same line as the symbol. So most of you have only yourself to blame for this.
    Last edited by MK27; 06-02-2009 at 08:19 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  14. #29
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,445
    Quote Originally Posted by Driver
    Just as horrible is this, a bit like the GNU one but worse, which I've seen from time to time:
    That is the Whitesmiths style, pointed out in post #19.

    Quote Originally Posted by MK27
    Yes, and in case anyone hadn't noticed, these abominations are all descended from the allmanic obscenity of not placing the opening brace on the same line as the symbol.
    So far, with the exception of the MK27 style, I find all these indent styles to be reasonable for reading, even though I would be reluctant to write with all but Allman and K&R. So much for "abominations".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #30
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by laserlight View Post
    So far, with the exception of the MK27 style, I find all these indent styles to be reasonable
    I am sure there is a whole pack of cowards here who totally empathize with the obvious (and elegant) logic of my indentation style and have even done similar things themselves, when allowed, but are afraid to speak up because it is too late -- history has spoken*.
    Code:
              /* command line arguments */
            if (argc>1) { if (strlen(argv[1])>MPTH-1) { puts("Filename is too long!"); return 0; }
                    if (argv[1][0]!='-') tmp=argv[1]; /* filenames starting with a dash will need ./ */ 
                    while ((opt=getopt(argc, argv, options))>0) switch (opt) {
                            case ('?'): usage(argv[0]); return 0;
    This is like a thousand line project with 2 header files in allman.

    * but that doesn't make it right you fascists
    Last edited by MK27; 06-02-2009 at 08:42 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Page 2 of 7 FirstFirst 1234567 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is curly braces here is a must?
    By mashour06 in forum C Programming
    Replies: 8
    Last Post: 04-25-2009, 04:41 PM
  2. Curly brace question
    By kenryuakuma in forum C++ Programming
    Replies: 12
    Last Post: 12-16-2008, 06:06 PM
  3. Placement new?
    By Elysia in forum C++ Programming
    Replies: 9
    Last Post: 02-26-2008, 03:50 AM
  4. My Placement come true
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 06-07-2004, 06:07 AM
  5. CIOS college placement tests
    By compjinx in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 12-13-2002, 01:33 AM

Tags for this Thread


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