View Poll Results: Which bracer style?

Voters
39. You may not vote on this poll
  • Spuds way, {} on a separate line to the method name/parameters

    28 71.79%
  • the 'other' way, mixing {} in with your code to hide them away from unsuspecting programmers

    9 23.08%
  • I use VB...whats a bracer for?

    2 5.13%
Page 1 of 4 1234 LastLast
Results 1 to 16 of 51

Thread: How do you do your braces {} ?

  1. #1
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,508
    Thanks
    336
    Thanked
    320 times in 255 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre

    How do you do your braces {} ?

    Ok, bit of a geeky poll here...as a result of some annoying programmers out there who insist on formatting their code in a certain way that makes it almost unreadable.

    So I was wondering if its just me that can't stand people who don't format their code 'properly' (as i see it ) or if i'm in the minority, and really need to adjust to this different way of doing things.

    Up until now I will have confused you, so heres what I mean.

    My (and I think the correct, logical) way of doing things:

    Code:
    public bool myMethod
    {
        String strExample;
        .... etc
    }

    or the (in my view) retarded way [edit: I know its not retarded, and there are historical reasons for this method..i was just a bit stressed in my original post ]

    Code:
    public bool myMethod {
      String strExample;
      .... etc
    }
    Is it just me? or do others also get frustrated at this? If you are always working with a decent IDE or with simple methods/classes/control structures its not really a problem, but if you are occasionally forced to use something like JBuilder, or end up with textpad/notepad (ie something that doesnt highlight start/end bracers well) it can be a nightmare to see where something starts and ends.

    With my formatting of bracers its always clear which bracer matches which, as they are always lined up together..it makes your code much cleaner to read, and looks nicer..obviously there are exceptions eg single line if statements where ommiting the brackets entirely is cleaner..but for large methods etc I find it REALLY annoying.

    Posted this as i'm sitting here going through a lecturers code and 'corrrecting' it to make sense..so whats your opinoin?
    Last edited by Spud1; 26-02-2007 at 03:27 PM.

  2. #2
    Banned arbitor's Avatar
    Join Date
    Feb 2007
    Posts
    1,849
    Thanks
    0
    Thanked
    7 times in 7 posts
    i liek your way,in editing a load of scripts on my game server last night i cam across the second way took me a few mins to figure out what wernt with what.

  3. #3
    Flower Child stytagm's Avatar
    Join Date
    Aug 2004
    Location
    London
    Posts
    754
    Thanks
    47
    Thanked
    23 times in 18 posts
    Personally I like your way, and it is pretty much the norm these days, but some of the older coders in our company layout their code with the Opening brace on the same line as the declaration.

    There is an argument that having the Opening brace on it's own line is redundant and unnecessary, as the closing Brace is in-line with the Function declaration already, there is no need to have a second line with the Opening brace on it, also lining up. It's just wasted space.

    If I remember correctly, The guy who wrote Code Complete is one person who argues for the "old way" (with the Opening brace on the same line as the declaration).

    So it comes down to personal preference. It doesn't bother me because something like Resharper can reformat the code instantly, and also sorts out any indentation issues at the same time.
    They told me I was gullible ... and I believed them.

  4. #4
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    I personally prefer:

    Code:
    type decl-name() {
    }
    Not sure why, it just seems tidier to me, plus fiddling around with python you're pretty much forced to use this syntax style.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  5. #5
    Does he need a reason? Funkstar's Avatar
    Join Date
    Aug 2005
    Location
    Aberdeen
    Posts
    19,874
    Thanks
    630
    Thanked
    965 times in 816 posts
    • Funkstar's system
      • Motherboard:
      • Gigabyte EG45M-DS2H
      • CPU:
      • Intel Core2Quad Q9550 (2.83GHz)
      • Memory:
      • 8GB OCZ PC2-6400C5 800MHz Quad Channel
      • Storage:
      • 650GB Western Digital Caviar Blue
      • Graphics card(s):
      • 512MB ATI Radeon HD4550
      • PSU:
      • Antec 350W 80+ Efficient PSU
      • Case:
      • Antec NSK1480 Slim Mini Desktop Case
      • Operating System:
      • Vista Ultimate 64bit
      • Monitor(s):
      • Dell 2407 + 2408 monitors
      • Internet:
      • Zen 8mb
    it's a long time since i needed to do this, but i always prefered the supposedly retarded way. It means you get more lines on screen at the same time

  6. #6
    radix lecti dave87's Avatar
    Join Date
    Sep 2005
    Location
    England
    Posts
    12,806
    Thanks
    657
    Thanked
    931 times in 634 posts
    • dave87's system
      • Motherboard:
      • Asus
      • CPU:
      • i5 3470k under Corsair H80 WC
      • Memory:
      • 8gb DDR3
      • Storage:
      • 240gb SSD + 120gb SSD
      • Graphics card(s):
      • Asus HD7950
      • PSU:
      • XFX 600w Modular
      • Case:
      • Lian Li PC-A05FNB + Acoustipack
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • 2x Dell S2309W (1920x1080)
      • Internet:
      • BT Infinity Option 2
    The retarded line does make sense sometimes, though if I look at code, I find it easier to read Spud's way...

  7. #7
    Metier9
    Guest
    When i used to code it was the non-retarded way and then i started doing the retarded way as after a while it was easier to read .

  8. #8
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    Your way is correct and that's how I standardise my code and anyone who's stuck code in our repository. It's better as it's easier to read and generally see what's going on where.

  9. #9
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts
    what about the i have an IDE with add-ins that do all that silly formatting work for me?

    Not too mention nicely drawing pollygons around the braces/brackets in scope so its always very clear.
    throw new ArgumentException (String, String, Exception)

  10. #10
    Senior Member manwithnoname's Avatar
    Join Date
    Dec 2005
    Posts
    1,050
    Thanks
    17
    Thanked
    26 times in 25 posts
    I find 'my code' the easiest to read , my brackets are formatted in the 'non-retarded' way.

    I don't use an IDE, not from choice, but I imagine if you use them either is just as readable - assuming pretty colours for comments and keywords etc. But spare a thought for the poor sod who has to use some arcane 2 tone text editor to look at some code please...

    Quote Originally Posted by Metier9 View Post
    When i used to code it was the non-retarded way and then i started doing the retarded way as after a while it was easier to read .
    Out of interest do use a colourful IDE?

  11. #11
    Comfortably Numb directhex's Avatar
    Join Date
    Jul 2003
    Location
    /dev/urandom
    Posts
    17,074
    Thanks
    228
    Thanked
    1,027 times in 678 posts
    • directhex's system
      • Motherboard:
      • Asus ROG Strix B550-I Gaming
      • CPU:
      • Ryzen 5900x
      • Memory:
      • 64GB G.Skill Trident Z RGB
      • Storage:
      • 2TB Seagate Firecuda 520
      • Graphics card(s):
      • EVGA GeForce RTX 3080 XC3 Ultra
      • PSU:
      • EVGA SuperNOVA 850W G3
      • Case:
      • NZXT H210i
      • Operating System:
      • Ubuntu 20.04, Windows 10
      • Monitor(s):
      • LG 34GN850
      • Internet:
      • FIOS
    Code:
    type decl-name( type param1, type param2 )
    {
        if( variable == value )
        {
            do;
            lots;
            of;
            things
        }
    }

  12. #12
    The King of Vague Steve B's Avatar
    Join Date
    Oct 2005
    Location
    Glasgow
    Posts
    5,051
    Thanks
    116
    Thanked
    67 times in 63 posts
    yep hexxy has it the way i do it, only he forgot his semi-colon after things

  13. #13
    bored out of my tiny mind malfunction's Avatar
    Join Date
    Jul 2003
    Location
    Lurking
    Posts
    3,923
    Thanks
    191
    Thanked
    187 times in 163 posts
    • malfunction's system
      • Motherboard:
      • Gigabyte G1.Sniper (with daft heatsinks and annoying Killer NIC)
      • CPU:
      • Xeon X5670 (6 core LGA 1366) @ 4.4GHz
      • Memory:
      • 48GB DDR3 1600 (6 * 8GB)
      • Storage:
      • 1TB 840 Evo + 1TB 850 Evo
      • Graphics card(s):
      • 290X
      • PSU:
      • Antec True Power New 750W
      • Case:
      • Cooltek W2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Dell U2715H
    Can't believe this still comes up. Personally I prefer the opening brace to be on the same line as the declaration / statement And it depends on which language (and possibly complier) hex is simulating on whether or not the last semi-colon is required or 'implied'. Oh and the last place I worked at where had a say in coding standards the rule around this was:

    Do it whichever way you want but if you're editing someone else's code keep them the same or convert the whole bloody thing

    I also write if statements the long way even when I only have one line of code associated with the if statement:
    Code:
    if (something == true) {
       doSomething();
    }
    And not this evil way:
    Code:
    if (something == true)
       doSomething();
    Last edited by malfunction; 27-02-2007 at 12:29 AM.

  14. #14
    Member
    Join Date
    Jan 2007
    Location
    Manchester
    Posts
    56
    Thanks
    0
    Thanked
    0 times in 0 posts
    PHP Code:
    if (condition) {
        
    line of code;
        
    line of code

    I fail to see how it's retarded at all. You can still see that it lines up perfectly. Plus you get more code on your screen.

    I think the actual point is why you'd ever want bracers to matchup? I want the start of the indentation if and the end of the indentation } to match up.

    I guess this way makes more sense in languages (such as perl) which you can't have an if without a block following it.

  15. #15
    The King of Vague Steve B's Avatar
    Join Date
    Oct 2005
    Location
    Glasgow
    Posts
    5,051
    Thanks
    116
    Thanked
    67 times in 63 posts
    if you're nesting if's it becomes much easier to debug if theres braces missing. braces should always line up imo

  16. #16
    awm
    awm is offline
    Senior Member
    Join Date
    Apr 2006
    Location
    US
    Posts
    920
    Thanks
    4
    Thanked
    7 times in 7 posts
    I write my code like this:
    Code:
    type function() {
        if (someVar) {
            doSomething();
        }
    }
    It'll sound kind of weird, but having the extra line return bothers me, but so does not having braces on a 1 line if statement. I guess it's all personal preference.

Page 1 of 4 1234 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •