4 ms·
I can't think of "forcing everyone to use the same conventions for indentation" as a purely good thing, any more than "forcing everyone to write comments in 18t
by 4bpp 15y ago
I can't think of "forcing everyone to use the same conventions for indentation" as a purely good thing, any more than "forcing everyone to write comments in 18th-century English" would be.
Sure, you make it easier for the random onlooker to be prepared to always immediately understand what is going on, but at the same time, the programmer who writes for his own perusal or that of a small team of known others will find themselves restricted by a totalitarian scheme telling them what they can express and what they can't. The assumption that most code is written for most people to read is simply not true, and code that is intended for the masses has always been able to deal with the problem by imposing style guidelines.
- sanxiyn 15y agoI can't understand how forcing coding convention can result in "being restricted by a totalitarian scheme". We are writing in a formal language instead of English. Style is the last place you want creativity. Use you creativity to express algorithms, not brace styles.
- 4bpp 15y agoBut it's not simply a matter of creativity. Apart from contentious instances pertaining to the complete omission of indentation (if (sdfg) { a; b; }), there are also occasional cases where I'd argue that semantically, you have a block, but syntactically, you don't; for instance, I've always very much favoured the approach when writing OpenGL code to indent everything between a glBegin and glEnd to separate the vertex data from the surrounding code and make it immediately obvious how objects in the scene are grouped. I think several indentation-based languages would ignore the initial indent increase here and consider the indent decrease before the glEnd to be the end of the block containing the group of statements...
- sanxiyn 15y agoYes, that is useful. That's why Python has with statements, for example. C++ RAII or Java try-with-resources can be used similarly. http://www.python.org/dev/peps/pep-0343/ http://www.python.org/dev/peps/pep-0343/
- bickfordb 15y agoActually, it's not as totalitarian as you imply. It's just a different way to express blocks of code. Languages which mark blocks using whitespace indentation (such as Python or Haskell) often don't force any particular amount of indentation. Consecutive lines with the same amount of whitespace prefix are considered be a part of the same block. Most projects/companies have indentation/style standards so that code can be communicated across individuals. Once you add in the indentation style, braces look redundant and are just extra noise and chances for error. I must admit, though, totalitarian systems often help people work together :)