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. #46
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    K&R or read all of Thantos' posts!
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  2. #47
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Thantos View Post
    Allman style or death!
    I think you mean:
    Code:
    all
    
    man
                      style
    
    
    
    or  
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
                                            DEATH!
    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

  3. #48
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Wel, I use Allman style if it's some long code block, like a whole class or something with a bunch of code, otherwise I use the other one. The one which looks like this:
    Code:
    void SayHi(){
            std::cout<< "Hi!" <<std::endl;
    }
    Currently research OpenGL

  4. #49
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    Gawd! So much freedom given to the C/C++ programmer. How would you feel about coding in Python, where consistent indentation is actually part of the required syntax?

    I programmed a while in Python before I started with C and I still find the freedom a little disconcerting. Logically I'm drawn toward the Allman style, which visually seems more suitable for my neurotic mind. I'm the kind of person who can't concentrate if there's a book on the desk that's sitting at an angle. In the local library as a kid I'd walk up and down the shelves making sure every book was pushed back as far as it would go. When I'm walking the dog if I look down and one of his ears is turned inside out it drives me crazy - I have to stop and flip it back over. That kind of thing.

    I think anyone with this kind of mental illness will be drawn to the Allman style. It's Feng Shui, man!

  5. #50
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Sharke View Post
    I think anyone with this kind of mental illness will be drawn to the Allman style. It's Feng Shui, man!
    Feng Shui for dim-wits, I think you mean. A sort of false Feng Shui, aka anal retentiveness -- you are much closer to the truth when you call it neurotic.

    I studied perl before C and had the exact opposite experience re: formatting and indentation. Not that I did not systematically indent and format my code, I just did in a somewhat more concise manner. The perl issue around "use strict" (pretty much settled by now) might be a parallel since it involves scoping, but in a syntactically meaningful way.

    However, I am gradually enjoying more widespace as I mature. But I would never go allman unless forced to.
    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. #51
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Sharke View Post
    I'm the kind of person who can't concentrate if there's a book on the desk that's sitting at an angle. In the local library as a kid I'd walk up and down the shelves making sure every book was pushed back as far as it would go. When I'm walking the dog if I look down and one of his ears is turned inside out it drives me crazy - I have to stop and flip it back over. That kind of thing.

    I think anyone with this kind of mental illness will be drawn to the Allman style. It's Feng Shui, man!
    You might want to get some SSRI's from your doctor and see if that helps with your OCD. I might be a little obsessive, but if nowhere near as bad as that.
    "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

  7. #52
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    Quote Originally Posted by cpjust View Post
    You might want to get some SSRI's from your doctor and see if that helps with your OCD. I might be a little obsessive, but if nowhere near as bad as that.
    Nonsense! I'm just a little quirky that's all. It's not as if the book-straightening interferes with my obsessive hand washing or anything like that. I can pretty much get all of it done as long as there's nothing on the TV beginning with the letter "P."

  8. #53
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    However, if you make a "high quality code" mentioned on "Code Complete" book, using PDL you'll definetly prefer the #1 style.

    Code:
    //whenever the current element's value is more than the next element's
    if(element[i] > element[i+1]) {
      //then swap the current element to the next one
      swap(element[i], element[i+1]);
    }
    instead of..

    Code:
    //whenever the current element's value is more than the next element's
    if(element[i] > element[i+1])
    {
      //then swap the current element to the next one
      swap(element[i], element[i+1]);
    }
    Just GET it OFF out my mind!!

  9. #54
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by audinue View Post
    However, if you make a "high quality code" mentioned on "Code Complete" book, using PDL you'll definetly prefer the #1 style.
    What is this nonsense? Quality has nothing to do with style!
    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.

  10. #55
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by audinue View Post
    However, if you make a "high quality code" mentioned on "Code Complete" book, using PDL you'll definetly prefer the #1 style.

    Code:
    //whenever the current element's value is more than the next element's
    if(element[i] > element[i+1]) {
      //then swap the current element to the next one
      swap(element[i], element[i+1]);
    }
    instead of..

    Code:
    //whenever the current element's value is more than the next element's
    if(element[i] > element[i+1])
    {
      //then swap the current element to the next one
      swap(element[i], element[i+1]);
    }
    Still prefer the Allman style.

    Now here is a kicker: If you can't handle using any spacing/bracket style that is throw at you then you won't be very useful. Allman might be my preferred style but if I'm touching code in a different style then I'll use the same style.

  11. #56
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >if you make a "high quality code" mentioned on "Code Complete"
    >book, using PDL you'll definetly prefer the #1 style.

    I don't see any meaningful difference. Could you point out why the #1 style is so preferred over the #2 style when using PDL?
    My best code is written with the delete key.

  12. #57
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is PDL?
    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

  13. #58
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    Quote Originally Posted by laserlight View Post
    What is PDL?
    Program Design Language?

  14. #59
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Elysia: Did I say styles absolutely does something to quality?


    Prelude: Did you try it?
    Just GET it OFF out my mind!!

  15. #60
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by cpjust View Post
    You might want to get some SSRI's from your doctor and see if that helps with your OCD. I might be a little obsessive, but if nowhere near as bad as that.
    I'm in the terrible position of having a family member with severe obsessive compulsive disorder. Needing to have things at just such an angle is not even remotely close to the horrors. I don't want to get into the depressing details, but it's not about quirkiness. It's a complete inability to function in the real world.

    Have you seen Jack Nicholson in the movie "As Good As It Gets?" That doesn't even remotely come close. It's a debilitating, terrible, awful, disease that not only ruins your own life but that of everybody around you who cares about you.

    Jeez.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

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