View Poll Results: Which style of if do you use?

Voters
63. You may not vote on this poll
  • Style #1

    18 28.57%
  • Style #2

    37 58.73%
  • Style #3

    6 9.52%
  • Other

    3 4.76%
Multiple Choice Poll.

Which style of if loops is most common?

This is a discussion on Which style of if loops is most common? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; does anyone do this? Code: if( 1 ) { x++; }else{ //same line x--; } i think it looks much ...

  1. #31
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    does anyone do this?

    Code:
    if( 1 )
    {
    	x++; 
    }else{              //same line
    	x--;
    }
    i think it looks much more solid
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  2. #32
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    int main()
    {
        try {
            while(condition)
            {
                if(stuff)
                {
                    dothings;
                    dothings;
                }
                else
                    meh();
             }
        }
        catch(Exception e) { 
            e.what(); 
        }
    }
    void meh()
    {
        do {
            int nRet = thingz();
            if(nRet == -1) break;
        } while(nRet != 0);
    }
    I have a lot of odd rules, however generally sticking to number 2 (do try and catch don't actually have that high a ratio in my code really). Sometimes I inline small statements following an if too, just if putting it on a newline puts it out of place. Also, 1-2 space indentation is killer, I don't know how some people swear by it. I need like 4-6 spaces per tab at least.
    Last edited by Tonto; 08-22-2005 at 01:29 AM.

  3. #33
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I accidentally voted 3, but use 2.

    >.<
    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

  4. #34
    Registered User
    Join Date
    Jun 2005
    Location
    Stockholm, Sweden
    Posts
    64
    Style #2 (BSD/Allman) is obiously the only correct coding style, since it's the one I use.

  5. #35
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    I use Allman/BSD, like a lot of the rest of you. It just seems much more clear and easier to read, especially when debugging.
    EntropySink. You know you have to click it.

  6. #36
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I see K&R used alot in tutorials and such, but I never liked it...
    Quote Originally Posted by Zach L.
    This Horstmann fellow was a sick, sick man...
    The same can be said about Whitesmith
    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

  7. #37
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Code:
    FILE *fp = fopen("out", "wt");
    is (usually) the same as
    Code:
    FILE *fp = fopen("out", "w");
    The latter uses the system default, which is usually 't' (text mode) but can be 'b' (binary mode). You can open a file in binary mode, too.
    Code:
    FILE *fp = fopen("out", "wb");
    So yes, t is a valid mode.
    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. #38
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Umm... are you sure that's in the right thread?

    EDIT: Nevermind... I didn't read the whole thread.
    EntropySink. You know you have to click it.

  9. #39
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I don't know what is most common, but I also normally use style 1.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to handle multiple cases which use common code?
    By tmaxx in forum C Programming
    Replies: 3
    Last Post: 10-03-2008, 07:42 AM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
  4. WS_EX_COMPOSITED style (double buffering) problems
    By JasonD in forum Windows Programming
    Replies: 2
    Last Post: 10-12-2004, 11:21 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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