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%

Thread: Curly Brace Placement

  1. #91
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    int and int* are two different types, just like float is a different type from int...
    char* a, b, c; is a wrong way to do it (ACCORDING TO ME) since it is rubbish and all that, go with more whitespace and everyone will read it equally!

    This is what I have to say about how I understand C++ ...
    Last edited by Akkernight; 06-16-2009 at 06:17 PM.
    Currently research OpenGL

  2. #92
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Sebastiani View Post
    >> 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.

    Yeah, I use a Scintilla-based IDE and it definitely has issues with horizontal scrolling (read: convulses). What do you use, by the way?
    On Windows I use VC++ & Eclipse.
    On Linux I just use Eclipse, although I haven't had to do much C++ in my new all UNIX work environment, only Java, Perl... but it looks like Eclipse has a plugin for almost everything.

    Quote Originally Posted by ಠ_ಠ
    how would you make 3 pointers consistent with your interpretation with *?
    I'd do this:
    Code:
    int* p1 = NULL;
    int* p2 = NULL;
    int* p3 = NULL;
    I never declare more than one variable on a line and I always initialize my variables.
    "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. #93
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by cpjust View Post
    I never declare more than one variable on a line and I always initialize my variables.
    hmmm... I prefer

    Code:
    int *foo, *bar;
    foo=bar=NULL;
    just because of less typing (less space is an added plus (added opportunity to make errors is a minus))
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  4. #94
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Call me crazy but

    Code:
    int *foo=NULL, *bar=NULL, *tooth=NULL, *nail=NULL, *three_rabbits_and_a_horse=NULL,
        *this=NULL, *that=NULL, *null=NULL;
    I don't mind a whole paragraph of those, as long as that paragraph is where it is supposed to be. If you leave them in alphabetical order you are extra special.
    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

  5. #95
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    And what about declaring your variables as close as possible to their first use? If you declare them all on one line at the top of your functions, you've been using C for too long.
    "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

  6. #96
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by cpjust View Post
    And what about declaring your variables as close as possible to their first use? If you declare them all on one line at the top of your functions, you've been using C for too long.
    Isn't initialization "use"? I won't bother arguing that tho.

    But do you see what I see, vis, allmanism leading to further perversion? Even in "complex sources" I've looked at, *most* functions do not need to be more than 20-50 lines. I'm working in perl right now, which is constantly declaring "my" variables in blocks of scope. That's alright 'cause perl saves a lot, declaration wise, with sigils & dynamism. But,
    if my functions
    double in line length
    suddenly I see people wanting
    to declare in each block, because now what
    supposedly made reading easier, needs to
    compensate for the ways in which
    it makes reading harder.

    Which is ass backward. Because instead of compressing all your variable declarations into one paragraph at the beginning, you now have to add *more* vertical insertions...because you had *too many* to start with.

    Allman == dope.
    Last edited by MK27; 06-16-2009 at 09:32 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

  7. #97
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by MK27
    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 wait... the * binds to the name in the grammar!

    Heheh, I tend to use T* name in C++ and T *name in C. Selective consistency

    EDIT:
    Quote Originally Posted by MK27
    Because instead of compressing all your variable declarations into one paragraph at the beginning, you now have to add *more* vertical insertions...because you had *too many* to start with.
    If you had too many variables to start with, you should create a helper function, not change your indent style.

    Declaring variables near first use means that the variable lives in the tighest scope possible. This use of local scope makes it easier to reason about your programs, and is precisely the point for local variables. Another reason would be to avoid unnecessary work, e.g., performing some relatively expensive initialisation prematurely (but I would regard this as more of a C++ problem due to potentially expensive constructors... unless you are a dumb C programmer).

    EDIT #2:
    Oh, and I have been informed:
    *closed by request of the OP*
    Last edited by laserlight; 06-16-2009 at 10:33 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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, 07:06 PM
  3. Placement new?
    By Elysia in forum C++ Programming
    Replies: 9
    Last Post: 02-26-2008, 04: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, 02:33 AM

Tags for this Thread