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; Originally Posted by brewbuck It's a debilitating, terrible, awful, disease that not only ruins your own life but that of ...

  1. #61
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by brewbuck View Post
    It's a debilitating, terrible, awful, disease that not only ruins your own life but that of everybody around you who cares about you.
    This person insists on using the allman style then, is what you are trying to say.
    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

  2. #62
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by MK27 View Post
    This person insists on using the allman style then, is what you are trying to say.
    LOL!
    "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

  3. #63
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    So, if somebody is having trouble understanding some concept, it's considered extremely impolite to call them a "retard."

    Yet somehow it is acceptable to refer to somebody who prefers certain things to be in very certain ways, as "obsessive compulsive?"
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #64
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by brewbuck View Post
    So, if somebody is having trouble understanding some concept, it's considered extremely impolite to call them a "retard."

    Yet somehow it is acceptable to refer to somebody who prefers certain things to be in very certain ways, as "obsessive compulsive?"
    both of those examples are A-OK!
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  5. #65
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by brewbuck View Post
    Yet somehow it is acceptable to refer to somebody who prefers certain things to be in very certain ways, as "obsessive compulsive?"
    I have ADHD which required a very strenuous diagnosis including *all* of my primary school records (inc. notes about behavior, crime, and punishment). It was at that point I actually came to understand the extent of the effect of something from which I have always "suffered" -- nb. my grades with a very few severe exceptions would always average far above average, and so these "consequences" were masked. So it always gets my hackles up when I hear some bs about how "ADHD" doesn't really exist; to me it is all chicken before the egg stuff intended to blame the victim. And joking around about this stuff may encourage people to believe it is all just a joke about whatever trend in social reality they perceive as parallel to ADHD.

    So, I'm sorry brewbuck, if your family member insists on the allman style dispite all these warning signs, then retards or not, I will still see obsessive compulsive disorder everywhere I turn my eye.
    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

  6. #66
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    >> Elysia: Did I say styles absolutely does something to quality?

    As a matter of fact, you did (and even emphasized it):

    However, if you make a "high quality code" mentioned on "Code Complete" book, using PDL you'll definetly prefer the #1 style.
    >> Prelude: Did you try it?

    I've actually seen posts by Prelude that use this style, so the answer to that would be "yes". At any rate, Preludes question was "Could you point out why the #1 style is so preferred over the #2 style when using PDL?", which you conveniently didn't answer.

  7. #67
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Personally I use
    Code:
    void function() {
        if(something) {
            puts("Really something.");
        }
        else {
            puts("Not something.");
        }
    }
    I'm not quite sure why, but I suspect it's the style that the very first book on C I read used.

    I know there has been discussion on this before (because I was the person who started the last poll on this!), but I'll just summarize my peculiarities of style:
    • I indent switch statements like so:
      Code:
      switch(x) {
      case 1:
      case 2:
          break;
      default:
          break;
      }
      That's mainly for horizontal whitespace reasons.
    • I like to put the operator on the next line if I have to wrap code, e.g.
      Code:
      if(pointer && pointer->ref_count() > 0
          && !lookup_table.find(pointer)) {
      
          /* code */
      }
      No particular reason, except that you have to decide one way or the other (or not), and I think I dimly remember reading somewhere in a GNU manual that this was their preferred style. (Though I'm not sure how much weight that has since their GNU indentation style isn't very appealing.)
    • I like to say "int *x" rather than "int* x". Again, no particular reason. I should mention though that I was working on a project which insisted on "int* x", and after a little while I had no trouble switching to that style.


    The last point is why I think indentation doesn't really matter; as long as you are consistent and it's readable, that's good enough. I think it's just habit, and you can change habits if you need to.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #68
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,432
    Sometimes it may be just a "style," but sometimes it may have some meaning behind it.
    I have chosen a particular style mostly because I find it more readable.
    As for the T* vs T * debate, I tended to stick with T* because it's a type and I find * next to the name retarded, because * is NOT part of the name.
    Nowadays, I'm slowly leaning towards the middle ground: T * var for a reason. Mostly because T is the type it points to and * means it's a pointer. Thus I might do T* * var, because var points to a T*.
    So sometimes there is a reason behind our styles
    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.

  9. #69
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Yes, I know the arguments. (Or some of them anyway.)
    T* x: "T*" is the type, so the asterisk should go near the T.
    T *x: T is the type, and x is a pointer to it. Plus this syntax works better when you declare more than one variable.
    T* x: Well, don't declare more than one variable on a line. Or use a typedef.
    T *x: typedefs make it hard to tell that you're dealing with a pointer type.

    And back on topic: quite a few books I see use a "compressed" style of indentation, like what I posted above; I think it's to save space. Actually I do have one book that uses this style, though (it was a gift, okay, I wouldn't buy it normally):
    Code:
    int main()
        {
        return 0;
        }
    I hate it. :P I read the preface as to why the author uses that indentation style, and apparently he originally used Allman style; but then a colleague started using this style, and he got used to it, and there you have it. The funny part is that the colleague switched over to his original indentation style.

    [edit] 7,400th post! Shh, Elysia. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #70
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    >> And back on topic: quite a few books I see use a "compressed" style of indentation, like what I posted above; I think it's to save space.

    That's pretty ugly.

    >> Well, don't declare more than one variable on a line. Or use a typedef.

    I place the modifier directly next to the type, unless it's a multivariable declaration, eg:

    Code:
    Type*
    	ptr;
    	
    Type
    	* begin, 
    	* end;

  11. #71
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You see what I mean? Two different styles, depending on whether you're declaring one variable or more than one. It should be easy to add another variable; just type , *p.

    But ignore me, because is my opinion is not steadfast (since I've switched back and forth) -- or does that make me more objective? Whatever.

    Incidentally, while we're talking about style, does anyone indent the contents of namespaces? Or extern "C"s?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #72
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    >> Incidentally, while we're talking about style, does anyone indent the contents of namespaces? Or extern "C"s?

    Nope. I probably should, for consistancy's sake, but I just can't do it (I use a lot of nested namespaces, and so the implications of reading a class declaration starting in the middle of the editor just doesn't feel right). Do you?

  13. #73
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    No way! I like nested namespaces too. When I have namespaces like Callis::GUI::Parser::Test, it would be absurd to indent them (even though this is a widescreen display . . . .)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #74
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I usually indent namespaces (and pretty much anything that's inside braces), but if it was something really nested like that, I'd probably just indent it once for all the namespaces. Although, I guess it would be just as easy to use the horizontal scroll bar to move over if it's indented a lot... Maybe that would ........ off the vi people enough to switch to a real IDE.
    "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

  15. #75
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Elysia View Post
    Sometimes it may be just a "style," but sometimes it may have some meaning behind it.
    I have chosen a particular style mostly because I find it more readable.
    As for the T* vs T * debate, I tended to stick with T* because it's a type and I find * next to the name retarded, because * is NOT part of the name.
    Congrats -- you've won me over on this one. I'm gonna start to use char* ptr instead of char *ptr. The later was just a habit I started out with.

    But I'll never dig the allman ("all whitespace" would be better). Compressed K&R all the way.

    [edit: I changed my mind again later...]
    Last edited by MK27; 06-16-2009 at 03:44 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

Page 5 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