## Curly Brackets Go Where?

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

## How do you do your bracketing?

Same line
88
48%
New line
88
48%
OTTERS!
7
4%

phlip
Restorer of Worlds
Posts: 7557
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

### Re: Curly Brackets Go Where?

I'd call it "irrelevant". The centre of a pair of brackets != the centre of a single bracket.

Code: Select all

`enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}`
[he/him/his]

hotaru
Posts: 1042
Joined: Fri Apr 13, 2007 6:54 pm UTC

### Re: Curly Brackets Go Where?

phlip wrote:I'd call it "irrelevant". The centre of a pair of brackets != the centre of a single bracket.

brackets almost always come in pairs. in most programming languages, you can forget about the "almost".

Code: Select all

`factorial = product . enumFromTo 1isPrime n = factorial (n - 1) `mod` n == n - 1`

phlip
Restorer of Worlds
Posts: 7557
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

### Re: Curly Brackets Go Where?

Yes, and it looks neater if you line the centre of one up with the centre of the other.

So why are we talking about the centre of the pair?

Code: Select all

`enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}`
[he/him/his]

hotaru
Posts: 1042
Joined: Fri Apr 13, 2007 6:54 pm UTC

### Re: Curly Brackets Go Where?

phlip wrote:Yes, and it looks neater if you line the centre of one up with the centre of the other.

So why are we talking about the centre of the pair?

because it makes more sense to have the brackets open toward the center of the pair than to have them open away from it.

Code: Select all

`factorial = product . enumFromTo 1isPrime n = factorial (n - 1) `mod` n == n - 1`

Area Man
Posts: 256
Joined: Thu Dec 25, 2008 8:08 pm UTC
Location: Local

### Re: Curly Brackets Go Where?

hotaru wrote:brackets do have a common center, to the right of the opening bracket and to the left of the closing bracket.
also, do you really say /ˈsɛntreɪ/, or just spell it that way?
---
so what would you call the point in the middle of a set of brackets?
---
brackets almost always come in pairs. in most programming languages, you can forget about the "almost".

The space separating the brackets I call "between". Delineating kewords also come in pairs and have a "between". Your some_function() example suffers from variable column padding distance between brackets. Brackets (and kewords) open and enclose scope which they mark, which may or may not have a centre, but definitely have a between.

Your pair of shoes also have a "common centre", but you can't stack them vertically according to that.

And I say it "sentr" (actually, it probably comes out more like "senrr"); do you say "sentair" or "sentuhr"?
Centre, from Latin "centrum"

hotaru
Posts: 1042
Joined: Fri Apr 13, 2007 6:54 pm UTC

### Re: Curly Brackets Go Where?

Area Man wrote:Your pair of shoes also have a "common centre", but you can't stack them vertically according to that.

but unlike brackets, a pair of shoes is generally not used to enclose a single contiguous region.

Area Man wrote:And I say it "sentr" (actually, it probably comes out more like "senrr"); do you say "sentair" or "sentuhr"?

neither. i say /ˈsɛntɝ/.

Area Man wrote: Centre, from Latin "centrum"

http://etymonline.com/index.php?term=center wrote:Spelling with -re popularized in Britain by Johnson's dictionary, though -er is older.

Code: Select all

`factorial = product . enumFromTo 1isPrime n = factorial (n - 1) `mod` n == n - 1`

Random832
Posts: 2525
Joined: Wed Oct 10, 2007 4:38 pm UTC

### Re: Curly Brackets Go Where?

Area Man wrote:I seem to recall vb enforcing indentation while requiring such verbosity in addition.

You recall wrong. The editor in visual studio does re-indentation (and case normalization, which doesn't change that the language is case-insensitive) all the time, but it's not required for the language.

Philwelch
Posts: 2904
Joined: Tue Feb 19, 2008 5:33 am UTC
Location: RIGHT BEHIND YOU

### Re: Curly Brackets Go Where?

Code: Select all

`{ //here is a bracket  //here is the center of a pair of brackets} //here is another bracket`

It's English, not any programming language, in which the center of a pair of brackets has to be horizontally between them.
Fascism: If you're not with us you're against us.
Leftism: If you're not part of the solution you're part of the problem.

Perfection is an unattainable goal.

Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

### Re: Curly Brackets Go Where?

Code: Select all

`(defun fact (n &optional (acc 1))  (if (= n 1)    acc    (fact (- n 1) (* acc n)      )    )  )<function name="hello" return-type="void">    <bracket>        <function-call function="printf">            <argument type="String">                <literal type="String">                    Hello world!                    </literal>                </argument>            </function-call>        </bracket>    </function>`

Is the above readable? Can we agree that brackets should be lined up above eachother on the same column now? And that XML sucks?
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

ash.gti
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

### Re: Curly Brackets Go Where?

Oh man, i know someone that used to write code like that and it always drove me crazy. Especially when I had to look at their HTML or XML.

Being able to see a <open> tag and looking directly aligned below it for the </open> closed version of the tag really makes looking at stuff easier.

Misaligned xml-like structures make things really hard to read.
# drinks WAY to much espresso

MaverickBJ
Posts: 0
Joined: Wed Mar 09, 2011 8:25 pm UTC

### Re: Curly Brackets Go Where?

Hypothetical situation...

if (some test) {
some code;
} else {
some more code;
}

Just me, but if you're going to have the line '} else {' all on 1 line, then for consistency, wouldn't it make sense to have your procedure name stubs done the same one, e.g.

public void someProc (param1, param2) { some code; } public void someProc2 (param1, param2) { some more code; }

To me, this is all retarded, and thus ALL curly brackets should have their own line for the simple purpose of consistency, there shouldn't be any argument that anybody could make for having it on he same line that won't have some sort of exception for putting it on an alternate line, and if this is true, then they should ALL be on a new line.

There, I've offered my 2 cents worth!

hotaru
Posts: 1042
Joined: Fri Apr 13, 2007 6:54 pm UTC

### Re: Curly Brackets Go Where?

MaverickBJ wrote:To me, this is all retarded, and thus ALL curly brackets should have their own line for the simple purpose of consistency, there shouldn't be any argument that anybody could make for having it on he same line that won't have some sort of exception for putting it on an alternate line, and if this is true, then they should ALL be on a new line.

Code: Select all

`if(some test){ some code; }else{ some more code; } `

consistent, and it doesn't have any precious-vertical-screen-space-wasting 1-character lines.

Code: Select all

`factorial = product . enumFromTo 1isPrime n = factorial (n - 1) `mod` n == n - 1`

enk
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark
Contact:

### Re: Curly Brackets Go Where?

Go did it RightTM:

http://golang.org/doc/go_faq.html#semicolons wrote:the advantages of a single, programmatically mandated format for all Go programs greatly outweigh any perceived disadvantages of the particular style
phlip wrote:Ha HA! Recycled emacs jokes.

stephentyrone
Posts: 778
Joined: Mon Aug 11, 2008 10:58 pm UTC
Location: Palo Alto, CA

### Re: Curly Brackets Go Where?

MaverickBJ wrote:Just me, but if you're going to have the line '} else {' all on 1 line, then for consistency, wouldn't it make sense to have your procedure name stubs done the same one, e.g.

Of course not. Functions aren't if/else blocks, and there's nothing inconsistent about applying different formatting to different syntactic elements of a language.

enk wrote:Go did it RightTM:

http://golang.org/doc/go_faq.html#semicolons wrote:the advantages of a single, programmatically mandated format for all Go programs greatly outweigh any perceived disadvantages of the particular style

No, they don't (and hence: no, it didn't). If trivial formatting details regularly constitute a sufficient obstacle that they interfere with your ability to read someone else's code, then you don't know the language very well. In the rare case where it really is an issue (certain horrible programmatically generated code, maybe) here are lots of beautifiers in the world, and it's not hard to use them.

That's not to say that Go got this wrong; it's only to say that it shouldn't (and doesn't) matter. There is no right or wrong.
GENERATION -16 + 31i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

enk
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark
Contact:

### Re: Curly Brackets Go Where?

stephentyrone wrote:
enk wrote:Go did it RightTM:

http://golang.org/doc/go_faq.html#semicolons wrote:the advantages of a single, programmatically mandated format for all Go programs greatly outweigh any perceived disadvantages of the particular style

No, they don't (and hence: no, it didn't). If trivial formatting details regularly constitute a sufficient obstacle that they interfere with your ability to read someone else's code, then you don't know the language very well. In the rare case where it really is an issue (certain horrible programmatically generated code, maybe) here are lots of beautifiers in the world, and it's not hard to use them.

That's not to say that Go got this wrong; it's only to say that it shouldn't (and doesn't) matter. There is no right or wrong.

Then what are you doing here in Religious Wars?

Anyway, the point is not about readability. It is about avoiding the debate. (Then what am I doing here in this thread? )
phlip wrote:Ha HA! Recycled emacs jokes.