What's your prefered program layout?

This is a discussion on What's your prefered program layout? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Thanks to adrian, I am able to show you the four techniques once again, (I hope it works i mean...) ...

  1. #46
    Unregistered
    Guest

    Lightbulb The four techniques, again

    Thanks to adrian, I am able to show you the four techniques once again, (I hope it works i mean...)


    #1) K&R
    Code:
        if (cond) {
             stmt1;
             stmt2;
             ...
        }

    #2) Allman
    Code:
     
        if (cond)
        {
            stmt1;
            stmt2;
            ...
        }

    #3) Whitesmith
    Code:
         if (cond)
            {
             stmt1;
             stmt2;
             ....
            }

    #4) Alternative
    Code:
           if (cond) {
               stmt1;
               stmt2;
               ...
               }
    tnx,
    ben

  2. #47
    Frustrated Programmer :( phantom's Avatar
    Join Date
    Sep 2001
    Posts
    163
    I would have thought a google search would find it though - that is what I'll be doing if I can't find the reports!
    I did a search on google and this was a good article I found.

    http://www.tjhsst.edu/compsci/cpp/intro/style.html
    My site to register for all my other websites!
    'Clifton Bazaar'

  3. #48
    back? dbaryl's Avatar
    Join Date
    Oct 2001
    Posts
    597
    I personally prefer the Allman format, with a slight variation at times. It's just that I've different resolutions and things like that, so sometimes you just have to make you code be more readable with what you got... luckily we need not worry about that now

    Does anyone know a good IDE / editor that does the indentation well (allman style)?
    This is my signature. Remind me to change it.

  4. #49
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Does anyone know a good IDE / editor that does the indentation well (allman style)?
    MSVC++ has an auto indention to the point where it drives me crazy. You can change the indention (it defaults to 4 spaces and I prefer 2), but you have to do so every time you open a project. It also seems to default to an allman style if you place the braces on their own lines.

    -Prelude
    My best code is written with the delete key.

  5. #50
    back? dbaryl's Avatar
    Join Date
    Oct 2001
    Posts
    597
    The line: Does anyone know a[n] good IDE / editor that does the indentation well (allman style)?

    ...should have read like this:

    Does anyone know an 'OK' FREE editor that does the indentation well (allman style)?
    This is my signature. Remind me to change it.

  6. #51
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> It also seems to default to an allman style if you place the braces on their own lines.

    Indeed it does. What struck me as odd is that MS seem to recommend Allman format, but if you look at any MS source, it is rarely so laid out, in fact, it is frequently a complete mess! I wonder if one of the real reasons for trying to keep the source of Windows secret is simply embarasment! (Spelling? - looks wrong to me).
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #52
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Originally posted by dbaryl
    The line: Does anyone know a[n] good IDE / editor that does the indentation well (allman style)?

    ...should have read like this:

    Does anyone know an 'OK' FREE editor that does the indentation well (allman style)?
    emacs rules.

    x-windows : x-emacs is good.

    I don't know if there's a windows implementation, there's definately a dos one.

  8. #53
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    >>I wonder if one of the real reasons for trying to keep the source of Windows secret is simply embarasment!

    I often wonder this myself. I know I have code like that. Its not the format, its just the hack-a-minute approach to some of my old code that makes it the code equivelant of a 100 year old bike tube after a ride through a nail factory. ... ... I'm better now.... Honest!

    But on the matter of bracket formatting; I feel strongly on this one. You can do what you like of course, but i 100% will NOT read anything longer than about 12 lines if its not in this format:
    Code:
    int main (void)
    {
       if (TRUE)
       {
          //statement
       }
    
       return 0;
    }
    I dont care if it takes an extra line on you're screen. Its not like we're still working on a Hercules or something. Theres plenty of lines to go around. (also they are not green lines which i personally think is a generally good improvement ) So the point i'm trying to make is: It looks neater. You can tell in an instant that there is both an opening and closing brace for each segment. You dont have to look to the end of some massive if () statement to double check that you didnt forget it (or that someone else didnt). It also makes it easy to find where you may have forgotten an opening or closing brace once the compiler generates its 14,000 errors basically stating that you're lacking a brace somewhere, go find it you idiot.

    And speaking of huge if () statements... What do you all do in this situation?

    if ( (statement1 > 1 || statement2 > 2 || statement3 > 3) && (ThisIsTrue || ThatIsTrue) && ThisIsALongStatement)
    How would you format that? Personally i would likely do:
    Code:
    if ( (statement1 > 1 || statement2 > 2 || statement3 > 3) &&
         (ThisIsTrue || ThatIsTrue) &&
         ThisIsALongStatement)
    but it gets confusing if you're statements are really something like:
    World.tile[PosAt.X - PosAt.OffsetX][PosAt.Y - PosAt.OffsetY].ObjRef[OBJ_TO_REF] > MAX_OBJ_ALLOWED
    etc etc....
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  9. #54
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> And speaking of huge if () statements

    Yes, I tend to stack them much as you have done if there are a lot of them. I dislike horizontal scrolling.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Page 4 of 4 FirstFirst 1234
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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