braces

This is a discussion on braces within the Tech Board forums, part of the Community Boards category; This may seem like a really strange thread, but im wondering why some programers do braces like this: Code: class ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475

    braces

    This may seem like a really strange thread, but im wondering why some programers do braces like this:

    Code:
    class myClass {  // open brace here
    
    public:
    void function();
    
    };  // close brace

    And some programmers like me do it this way:

    Code:
    class myClass
    {     // open brace here
    
    public:
    void function();
    
    };   // close nrace
    Please do not rib me for asking, but I am wondering which is the
    prefered use, and does it have any advantages above the other?

  2. #2
    Nothing is impossible! 74466's Avatar
    Join Date
    Jan 2006
    Location
    Bloemfontein South-Africa
    Posts
    29
    i use the 2nd, as i find it easier to see whether i have closed a brace or not.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    63
    It's a preference, but as with anything in programming some people will say it has to be a certain way. Readability is an important part of programming, so whichever way you find it easier to read and understand do it that way.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Both methods you posted are unacceptable.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Location
    Stockholm, Sweden
    Posts
    64
    Either way is fine, but the correct way is the second one since that's what I use.

    7stud, don't tell me you use GNU-style?

  6. #6
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    I generally use the first when writing Java or C, the second writing C++.
    It's usually good practice to follow the "official" standard for the language you're using, it's what most people who use the language will be used to seeing.

    C++ style (second) is supposedly be a bit easier when you're commenting out blocks of code but in practice it hardly matters.

  7. #7
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    i used to use the first type, but that was before i tabbed out blocks of code - using the second method, most IDE/text editors will tab out automatically, like this:

    Code:
    void myfunction ()
    {
              //when i hit return, cursor moves to the start of this line
              .
              .
              .
    }        //once i type the closing brace, it automatically moves in line with the opening brace
    making it easier to read/debug in general. thats my take on the point
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  8. #8
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    I want to see as much as possible on the screen. I use first style.
    Kurt

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    http://en.wikipedia.org/wiki/Indent_style
    In the absense of external standards (ie, when I'm doing my own stuff), I prefer the "one true brace style".

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    Quote Originally Posted by 7stud
    Both methods you posted are unacceptable.
    im interested in knowing why you feel that way, any elaboration?
    If a mime dies in the woods and no one is around to hear it, does it make a sound?

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    A fairly recent poll on bracing style.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #12
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Quote Originally Posted by sreetvert83
    im interested in knowing why you feel that way, any elaboration?
    They both lack indentation.

  13. #13
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you're all wrong. This is the only way to do it:
    Code:
    class myClass { /* open brace here */ public: void function(); }; //close brace
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  14. #14
    Registered User
    Join Date
    Jan 2006
    Posts
    63
    Quote Originally Posted by 7stud
    They both lack indentation.
    Doesn't this come down to the IDE you use to write your code in?

  15. #15
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    Code:
    #include <iostream> 
    int main() { std::cout << "Hello World!"; std::cin.get(); return 0; }
    This is the Majo-Sly Style. It saves more paper.
    Sent from my iPadŽ

Page 1 of 2 12 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. error: braces around scalar initializer...
    By Osiris990 in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2008, 02:22 PM
  3. What Do Braces Do?
    By jrahhali in forum C++ Programming
    Replies: 11
    Last Post: 04-18-2004, 04:14 PM
  4. Local stacks, curly braces
    By bennyandthejets in forum C++ Programming
    Replies: 2
    Last Post: 07-11-2003, 11:48 PM
  5. Replies: 1
    Last Post: 12-01-2001, 07:17 AM

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