• Staff Applications

    Hello fellow Marrilanders! We have reached a point for our staff team where recruiting new members is necessary — so we are opening up applications!
    If you are interested, you can find more information in this thread.

Computer programming question

Where do you put your curly braces?

  • Same line

    Votes: 8 40.0%
  • New line

    Votes: 12 60.0%

  • Total voters
    20

Dragonite

Have they found the One Piece yet
Join Date
Nov 2, 2018
Posts
117
Location
Whiterun, probably
Gender
Male
3DS FC
4682-8983-8215
IGN
Dragonite, usually
#3
Excuse me for not wanting to waste more lines than I have to for punctuation ლ(ಠ益ಠლ)
 

~Kilza~

A Hockey Boy
Join Date
Oct 28, 2018
Posts
6,766
Location
Edmonton, AB
Gender
Male
Time Zone
MST (UTC-7)
#4
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
83
Location
Garden of Oblivion
Gender
Male
Time Zone
GMT +8
#5
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

☆ POP/STAR ☆
Administrator
Join Date
Oct 23, 2018
Posts
624
Location
Nowhereville
AKA
Thunda, Regine
Gender
Female
Time Zone
EST
3DS FC
4184-1904-4290
IGN
Regine
#6
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. :hmm:
 

Moxie

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

Stralend

Dreamer of Faith
Join Date
Jan 6, 2019
Posts
248
Location
Neverland
AKA
Star; Sara;
Gender
Female
Time Zone
GMT + 1
3DS FC
5413-1220-4222
#8
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
Join Date
Nov 1, 2018
Posts
56
Location
California
AKA
Andrew
Gender
Male
IGN
Andrew
#9
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 Star
Staff Emeritus
Cabin 2
Join Date
Oct 24, 2018
Posts
854
Location
Sinnoh
Gender
Male
Time Zone
UTC +10
#10
It's gotta be the same line. It just looks.... wrong on a new line.
 

Wren

Regular Trainer
Join Date
Nov 1, 2018
Posts
146
#11
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

Cool doggo
Cabin 2
Join Date
Nov 1, 2018
Posts
79
Location
Dancefloor
Gender
Male
#12
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

Junior Trainer
Join Date
Jan 3, 2019
Posts
59
Location
Virginia
AKA
Chris
Gender
Male
Time Zone
UTC-05:00
#13
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
Join Date
Nov 1, 2018
Posts
56
Location
California
AKA
Andrew
Gender
Male
IGN
Andrew
#14
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.
 

Revan

I See the Light
Staff Emeritus
Join Date
Oct 28, 2018
Posts
486
Location
Kingdom of Corona
AKA
Ravey, Steve
Gender
Male
Time Zone
US Central Time
#17
I was taught new line but I do it same line because of the editors I use.
 
Top