Computer programming question

Where do you put your curly braces?

  • Same line

    Votes: 9 40.9%
  • New line

    Votes: 13 59.1%

  • Total voters
    22

Kyogre386

Regular Trainer
Join Date
Jan 3, 2019
Posts
105
Location
Virginia
AKA
Chris
Gender
Male
Time Zone
UTC-05:00


Which one are you?
 

-Rosen

Bored
Rainbow Rocket Grunt
Join Date
Nov 1, 2018
Posts
344
Location
Pittsburgh, PA
AKA
Cleb
Gender
Male
Same line folks are heathens and you can't change my mind
 

Dragonite

have they found the One Piece yet
Rainbow Rocket Grunt
Join Date
Nov 2, 2018
Posts
275
Location
Whiterun, probably
Gender
Male
3DS FC
4682-8983-8215
Switch FC
SW-8460-1905-2708
IGN
Dragonite, usually
Excuse me for not wanting to waste more lines than I have to for punctuation ლ(ಠ益ಠლ)
 

~Kilza~

The Sun Has Set
Rainbow Rocket Grunt
Account Disabled
Join Date
Oct 28, 2018
Posts
9,120
Location
Gone forever
Gender
Male
Time Zone
MST (UTC-7)
C++:
    if(buf[0] & (1 << 7)) {
        if(buf[0] & (1 << 6)) {
            op = 1;
        }
        else {
            writes++;
            op = 2;
        }
    }
    else {
        if(buf[0] & (1 << 6)) {
            accum -= (buf[0] & 63);
        }
        else {
            accum += (buf[0] & 63);
        }
    }
:^)

Technically I've done new line for my left curly bracket since I began working, but that's mainly because Visual Studio is set up to do that so hey, that's fine.
 

Ice_Dragon

The Fairy Dragon
Staff Emeritus
Join Date
Oct 31, 2018
Posts
91
Location
Garden of Oblivion
Gender
Male
Time Zone
GMT +8
I prefer the one on the right. It looks neater to me, especially in nested conditionals.

I haven't done programming in ages but that's the convention I've used in university.
 

Thundawave

♪ Aroma White ♪
Staff Emeritus
Rainbow Rocket Grunt
Join Date
Oct 23, 2018
Posts
1,179
Location
Nowhereville
AKA
Thunda, Regine
Gender
Female
Time Zone
EST
3DS FC
4184-1904-4290
Switch FC
SW-2896-2294-7693
IGN
Regine
Same line is what I’m used to for brackets in CSS code. But my main programming language is Python, which doesn’t use curly brackets for any sort of conditional. :hmmazurill:
 

Moxie

Veteran Ditz
Rainbow Rocket Grunt
Join Date
Nov 2, 2018
Posts
802
AKA
Daam
Gender
Male
For c programming I always used a new line. Using it on the same line is blasphemy!
 

Stralend

Dreamer of Faith
Rainbow Rocket Grunt
Join Date
Jan 6, 2019
Posts
294
Location
Neverland
AKA
Star; Sara;
Gender
Female
Time Zone
GMT + 1
3DS FC
5413-1220-4222
For C++ I always use a new line, simply because then you can just "hide" the statements in visual studio. It's pretty neat :D
 

Diarkia124

Master of Jacks
Rainbow Rocket Grunt
Join Date
Nov 1, 2018
Posts
207
Location
California
AKA
Andrew
Gender
Male
IGN
Andrew
I used to have my curly braces on the same line as the conditional but I've switched over to having it on a new line. I switched after I started doing things in Verilog where you use begin and end instead of { and } and it makes a lot of difference to me.
 

Dregran

Shocking Trainer
Staff Emeritus
Rainbow Rocket Grunt
Join Date
Oct 24, 2018
Posts
1,345
Location
Sinnoh
Gender
Male
Time Zone
UTC +10
It's gotta be the same line. It just looks.... wrong on a new line.
 

Wren

Adept Trainer
Rainbow Rocket Grunt
Join Date
Nov 1, 2018
Posts
382
Same line was what my first CS professors used, so that's what I use now. Plus it's easier to see what's nested in what.
 

Franciscosta

Communist Duck
Rainbow Rocket Grunt
Join Date
Nov 1, 2018
Posts
168
Location
Motherland
Gender
Male
I pretty much always use same line, unless it's on a new line for some reason and I'm too lazy to change it.
 

Kyogre386

Regular Trainer
Join Date
Jan 3, 2019
Posts
105
Location
Virginia
AKA
Chris
Gender
Male
Time Zone
UTC-05:00
Was curious to see the results before I weighed in myself. Surprised to find I'm in the majority, thought it would be more 50-50. I do new line, always. I think that's way easier to read in heavily nested branches/loops. I don't see how matching a brace to a statement could possibly be easier than matching a brace to a brace when trying to match things up. I was working with some code this week at work that used the same line unlike most of our code, and trying to comprehend the nesting was hell for me. It's so much easier for me at a glance to see what is nested in what by just matching similar looking characters at the same indentation. It looks way more symmetrical too, and I'm the kind of guy that wishes magnetic monopoles existed just so Maxwell's equations would be nicer.
 

Diarkia124

Master of Jacks
Rainbow Rocket Grunt
Join Date
Nov 1, 2018
Posts
207
Location
California
AKA
Andrew
Gender
Male
IGN
Andrew
Google supposedly uses clang formatting which has the braces on a separate line.

Example

On a side note, I should probably fix the implementation since I don't have to worry about unsigned ints type casting into normal ints if the MSB is 1.
 

Slix

Adept Trainer
Rainbow Rocket Grunt
Join Date
Nov 1, 2018
Posts
302
Location
Swimming with the Poliwag~!
Gender
Male
Same line. I've always done it that way, and it looks cleaner to me. Less line wasting.
 

ninetales

Advanced Trainer
Staff Emeritus
Join Date
Oct 29, 2018
Posts
814
I do it on a new line, way I was taught and it just feels right
 

Revan

Wound in the Force
Staff Emeritus
Join Date
Oct 28, 2018
Posts
645
Location
Malachor V
AKA
Ravey, Steve
Gender
Male
Time Zone
US Central Time
I was taught new line but I do it same line because of the editors I use.
 

Zedark

Sloooooooowbroooooooo
Rainbow Rocket Grunt
Join Date
Mar 3, 2019
Posts
104
Location
UK
AKA
Alex
Gender
Male
Time Zone
GMT
It's got to be a new line for me. I'm no professional dev but same line just looks too cluttered for me.
 

seaturtle

Spirit Bridge
Administrator
Rainbow Rocket Executive
Join Date
Oct 23, 2018
Posts
1,676
AKA
Chris
Gender
Male
Time Zone
MST
Switch FC
SW-3906-8627-4487
honestly it mostly depends what the professor wants for me heh. for personal projects i tend to go same line though.
 
Top