The Facts Behind the Code Indention Style War
experimentgarden.blogspot.com
experimentgarden.blogspot.com
I'd be interested in seeing some actual research into the relative usability and other factors of the various approaches. Until such time as someone proves it objectively one way or the other I'll use what I'm familiar with (K&R) in private code and the house style in the day job.
Every moment you spend cleaning up Windows-style EOL characters or transforming tabs into spaces (or vice versa) - or programming your editor to do so - is a moment of your life that could have been put to a better use.
With a standardized S-expression format (it could even be human-readable, as for example, Lisp source is) all possible source files which result in the same syntax tree would have the same canonical (by definition) representation. Yes, this means that parsers will need to parse comments rather than toss them, but implementing this minor trick is not a challenge for anyone who has read a few chapters of the Dragon Book (or its imitators.)
Your editor can still show you exactly what you want to see. And other people will have the same ability.
If you are using Eclipse (or whatnot) to magically reformat source to your personal tastes every time you edit anything, you have already quit pretending that the original raw human-readable representation is worth much. All I'm suggesting is to take this process to its logical conclusion.
Storing source as ASTs instead of ASCII would, among other things, increase the usefulness of revision control systems. It would eliminate the need for programmers to agree on any formatting style at all.
What about broken code, though, would I not be able to save that?
[FWIW, both examples suck. Use a case or switch statement.]
Go Tom, great stuff. Now all we've got to do convince is teach you to space it all out so I can read it
I switched to Allman after that: much to the relief of many people ;)
Having used python and small amounts of lisp, I also flirted with rolling up all the close parens/braces on the end of lines with no white space.
bottomline: because he is used to them. I feel the K&R style is easier to read because that is what I am used to.
I'm not worried about obsessing about compact code; this style just looks best to me. I'm consistent with my formatting, so I can glance at my code and know what I'm looking at. Actually, I can literally unfocus my eyes and I still know if I'm looking at a function, control structure within a function, or a class definition.
The important part, where taste comes in, is where code gets separated by empty lines. I consider code separated by empty lines akin to paragraphs.
For the reocrd, my indent settings:
-br -brs -nbfda -npsl -npcsAnd ultimately, consistency is most important. Your "style" only matters when you're starting your own project; I really hate it when people let their personal disagreements chop up a source file.
I've seen code that got confusing with K&R, especially when the programmer forgot to indent the next lines. And I really like the ability to adjust control flow with block commenting you have with braces-stand-alone.
I'm not looking to compress code. My goal is to make code as readable as possible. Anything I can do to make it explicitly clear what's going on I'm going to do. Code should not read like a mystery novel.
A single bracket on an otherwise empty line carries very little information, so why not reduce the strain on the eyes.
When I'm scanning code, lots of time I don't care about the control, I'm looking for what process takes place. Likewise, sometimes I'm just interested in control and could care less about process.
Braces-stand-alone lets me focus on each of these at a time. Especially if you get into an unusual control situation, perhaps with nested conditions, braces-stand-alone lets you isolate various control paths and change and test them.
It's not the end of the world or anything. As long as you understand the superiority of my position, of course (grin)
That way I can just look at the indentation to see where blocks start and end.
if(condition_variable==condition2)
/*{
//Block temporarily commented out.
condition_variable=condition1;
}*/ self.smile()