5 ms·
Why do people do that?! Seriously, why?
by biohacker42 18y ago
Why do people do that?! Seriously, why?
- benreesman 18y agoI 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.
- fortes 18y agoExactly -- for JS sytle see Crockford, who explains these in detail: http://javascript.crockford.com/code.html http://javascript.crockford.com/code.html
- DanielBMarkham 18y agoI'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.
- DanielBMarkham 18y agoI 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.
- makecheck 18y agoIn 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.
- jcl 18y agoThe 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 http://en.wikipedia.org/wiki/Indentation_style#K.26R_style
- mechanical_fish 18y agoThe Java style guide from Sun does this: http://java.sun.com/docs/codeconv/html/CodeConventions.doc5.html#2991 http://java.sun.com/docs/codeconv/html/CodeConventions.doc5.... The PEAR PHP coding standards recommend this: http://pear.php.net/manual/en/standards.php 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.
- biohacker42 18y agoMy order of language takeup: C++/Python/Lisp. But yeah it's a C thing. Never the less, this{ } Is an abomination!
- DanielBMarkham 18y agoIt'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.
- PaulMorgan 18y agoZend 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-formatting.html#coding-standard.php-file-formatting.indentation http://framework.zend.com/manual/en/coding-standard.php-file...
- DanHulton 18y agoI 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.)
- lucumo 18y agoI 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 :'(