Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

At least he's got enough sense to go braces-stand-alone

Those who hang the opening brace at the end of the line are the ones that drive me nuts.



Why do people do that?! Seriously, why?


I do that because I write a lot of JavaScript and semicolon insertion will mess you up if you don't make a habit of putting the opening brace on the end of the line. I suppose I could have two different styles but that sounds like an even worse option.


Exactly -- for JS sytle see Crockford, who explains these in detail: http://javascript.crockford.com/code.html


I've wrote a lot of Javascript, and have yet to get bitten by semicolon insertion. It's been a year or so since I really hacked JS, so I loaded up about 200K of code I've written and it's all braces-stand-alone.


The Java style guide from Sun does this:

http://java.sun.com/docs/codeconv/html/CodeConventions.doc5....

The PEAR PHP coding standards recommend this:

http://pear.php.net/manual/en/standards.php

And, as has been pointed out, if you don't do this in Javascript the JS interpreter will helpfully insert bugs for you (in the form of extra semicolons).

When Ruby uses braces at all, opening braces are placed at the ends of lines. (Usually the closing braces are on the same line, though... most multi-line Ruby blocks use the "do...end" keywords.)

The issue doesn't come up in Python at all, right? Likewise Lisp.

So it seems that only programmers who take up C as a first language will be exposed to the opening-brace-on-its-own-line style before they become used to the other style.


Zend framework also agrees with the PEAR PHP standard - 4 spaces for indentation with no tabs allowed:

http://framework.zend.com/manual/en/coding-standard.php-file...


My order of language takeup: C++/Python/Lisp. But yeah it's a C thing. Never the less, this{

} Is an abomination!


It's so wrong the poor folks can't even see it.

I understand that it came from Java. But even when I code in Java I'm braces-stand-alone. And this bit about semicolon insertion? Lies. All lies I tell you.


I use an IDE that allows code folding. With opening braces on their own line, I get:

  function bob()
  {
  --------------
On the same line as the function, I get:

  function bob() {
  ----------------
Much cleaner. Plus, I don't worry about being able to match braces against each other, I have an IDE that does that for me. (When my cursor is against one brace, it's partner is highlighted.)


I absolutely LOVE code folding. Unfortunately, it seems many editors mess it up in some way :-( Kate, gedit and Geany (which I suppose is representative for all Scintilla-based editors) all expand every code block below the line your editing when you start a string. Really annoying.

And sometimes they get confused about where the folding points are, which means you have to reload the file.

I just wish there was a good GUI editor on Linux with good folding support :'(


In at least one language (TCL), the interpreter cannot detect the block unless the brace is at the end of the line. Granted, I hate TCL as a language, so I won't defend it...but if someone were accustomed to moving between TCL and other things, they may tend to retain this habit.


The typical arguments are that the indentation style is more compact vertically and that it is used in a number of popular publications and projects (e.g. K&R, the Linux kernel).

http://en.wikipedia.org/wiki/Indentation_style#K.26R_style


I have no idea who started it but it's whacked.

You don't know when you see one line indented if it is a line continuation or conditional logic (or both) And god help you if you accidentally delete one of those opening braces -- it's impossible to spot sometimes unless you look closely.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: