News for hackers. Stuff that matters.
Re:Humans should think of sizeof() as a function, says Linus... by soup10 on Saturday May 30, 2015 @07:34AM (#9629816)
What kind of monsters don't use parentheses on sizeof. Is it the same guys that put { on new lines and have giant comment templates for every one line function.
Re:Humans should think of sizeof() as a function, says Linus... by MrBuddyCasino on Saturday May 30, 2015 @08:09AM (#9629902)
Ah, to join the bikeshedding: { on newlines make imho more sense, the block of code is visually balanced that way. We have high-res screens now, no reason to pretend we're still on 80 char terminals.

But work long enough in either one of those styles, and the other one will start to look strange.

Re:Humans should think of sizeof() as a function, says Linus... by heisenbit on Saturday May 30, 2015 @08:14AM (#9629911)
We got higher resolution and with it not taller but wider screens. So following your reasoning the { should be on the right ;-)
Re:Humans should think of sizeof() as a function, says Linus... by Retra on Saturday May 30, 2015 @09:37AM (#9630119)
What advantage does 'visually balanced' give? That's like saying the letter A is better than B because it's 'stands up better.'

Indentation is how you should identify blocks.

Re:Humans should think of sizeof() as a function, says Linus... by xamuel on Saturday May 30, 2015 @09:48AM (#9630153)
Indentation to identify blocks can break down in things like switch statements:

switch( c ) {

   case 'A':
     simple_stuff();
     break;

   case 'B': {
     int temporary_variable = 0;
     complex_stuff( temporary_variable );
 }
To me, the advantage of braces on newlines is it makes it extremely easy to tell where blocks start and end---whether you're using your favorite IDE, or reading the code on a blog, or reading the code with "cat". I actually think it's a case where Python has the design advantage on C (since if you do braces-on-newline consistently enough, you end up duplicating python but with superfluous braces added in).
Re:Humans should think of sizeof() as a function, says Linus... by JoeAltmaier on Saturday May 30, 2015 @10:06AM (#9630197)
Fundamentally, the problem is that braces are needed at all. Humans are bad at matching them up, so they don't match the humans' intention when indenting. Confusion.

It's all backward. The IDE should SHOW you the blocks somehow (background tone changes etc), and let you edit the blocking explicitely. If they look wrong, you select and hit a key. Now you're in agreement with the compiler.

Re:Humans should think of sizeof() as a function, says Linus... by MrBuddyCasino on Saturday May 30, 2015 @10:21AM (#9630241)
Yeah, this is one thing Python got right. You should indent anyway, and then the curly braces aren't needed anymore.

I don't know what the point is in pretending IDEs or advanced text editors don't exist.

Re:Humans should think of sizeof() as a function, says Linus... by douche on Saturday May 30, 2015 @10:16AM (#9630221)
I'm not seeing what the issue here is, besides that this won't compile because of mismatched braces. There is no need to put braces around the contents of a case block. Unless I'm switching on an enum, I rarely find a compelling reason to use switch/case, and there's usually a cleaner way to do it.
Re:Humans should think of sizeof() as a function, says Linus... by dllthomas on Saturday May 30, 2015 @03:35PM (#9631489)
"There is no need to put braces around the contents of a case block."

There is here.

In some dialects, you can only declare a variable at the start of a block. From the perspective of the compiler, a "case block" isn't actually a block, just stuff between labels. In order to declare temporary_variable, it may be necessary to put the braces, and it is probably best practice as temporary_variable may otherwise be exposed to later cases (and in C++, a jump over a variable declaration seems to produce an error).

Re:Humans should think of sizeof() as a function, says Linus... by michaelmior on Saturday May 30, 2015 @07:40AM (#9629828)
{ on new lines seems to have dominated the majority of code I've worked with although I've always preferred putting it on the same line myself.
Re:Humans should think of sizeof() as a function, says Linus... by harkyns_castle on Saturday May 30, 2015 @08:51AM (#9629997)
Most C++ codebases I've seen have the brace on a fresh line, most Java codebases at the end of the line (at a guess born of the Sun guidelines and default Eclipse formatting perhaps). I started with the former, but prefer the latter now.

To me its more about conserving an extra bit of vertical space... I like my methods/functions quite compact. In the past I liked the balanced nature of the braces though.

Makes absolutely no appreciable difference though of course, as long as you don't get into a formatting war with your team.

Re:Humans should think of sizeof() as a function, says Linus... by pivo on Saturday May 30, 2015 @08:07AM (#9629894)
I put it on the line that makes the code following it the most clear
Re:Humans should think of sizeof() as a function, says Linus... by MrBuddyCasino on Saturday May 30, 2015 @08:10AM (#9629903)
How do you handle auto-format? If a rules doesn't survive that, its not practical, at least for me.
Re:Humans should think of sizeof() as a function, says Linus... by pivo on Saturday May 30, 2015 @08:35AM (#9629960)
We don't use auto format for one because as far as I know it's not available for our languages (objective-c and swift)
Re:Humans should think of sizeof() as a function, says Linus... by vidarh on Saturday May 30, 2015 @08:44AM (#9629980)
I've never met an auto-formatter that I haven't hated the output of enough to not use it.
Re:Humans should think of sizeof() as a function, says Linus... by MrBuddyCasino on Sunday May 31, 2015 @10:55AM (#9634336)
Which ones would that be? The Eclipse one has a million knobs and twiddles, and is bearable in 95% of the time after fiddling with them a lot, which I'm okay with.
Re:Humans should think of sizeof() as a function, says Linus... by vidarh on Sunday May 31, 2015 @01:21PM (#9634799)
I must admit I haven't used Eclipse's auto-formatter because I've never met an IDE that haven't made me want to kill myself, and Eclipse is at the top of the list of IDE's I have never been able to stand more for than 5 minutes.