6 ms·
My favorite rule is 4.1.1; always use braces even where optional. I think a small fraction of the economy may have been damaged by the bugs caused by the silli
by datawander 13y ago
My favorite rule is 4.1.1; always use braces even where optional. I think a small fraction of the economy may have been damaged by the bugs caused by the silliness of leaving out optional braces and then having another developer come along and, well, you know how that goes :)
As someone who once read the Sun Java Style Coding [1] (which at a quick glance, appears to be a super set of the Google style guidelines) standard years ago and found it exciting and very helpful material, I unfortunately did not get such a kick skimming through this. Perhaps it's because after having read Clean Code [2], I feel that there is much missing that can lend itself to better code.
[1] http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html http://www.oracle.com/technetwork/java/javase/documentation/...
[2] http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882 http://www.amazon.com/Clean-Code-Handbook-Software-Craftsman...
- aragot 13y agoNothing personal with braces, but Java code is too verbose and it's so much pleasure, sometimes, when you can make it shorter.
- jrmenon 13y agoMore on braces, I am squarely in the Allman camp for the reasons described here: http://www.experimentgarden.com/2009/07/facts-behind-code-indention-style-war.html http://www.experimentgarden.com/2009/07/facts-behind-code-in... It is amazing the old-style K&R still persists. I think there was one more reason it was preferred in the early days which is not mentioned in the aforesaid link: storage space which was also expensive. The K&R style saves a new-line char which would be a significant saving in large codebases.
- Hovertruck 13y agoReading code with K&R braces is almost unbearable to me. I don't really know why, it just seems like a wasted line and visual clutter when reading code.
- frou_dh 13y ago} else { just looks too good to be wrong. I used Allman style for my first ~10 years of programming, then switched to "compact" style†, and didn't find it a big deal to adjust. Brace concerns melt away just like parens do in Lisp. † I think K&R does make use of new line braces, for functions.