Geeks – the good ones, anyway – get passionate about the smallest things. Should braces sit on a line by themselves, or be next to the if clause? Is dynamic SQL better than stored procedures? XSLT – good or evil? I’m often reminded of this Emo Philips sketch:
I was walking across a bridge and I saw a man standing on the edge, about to jump. So I ran over and said "Stop! Don’t do it. There’s so much to live for!"
He said, "Like what?"
I said, "Well, are you religious?"
"Yes"
I said "Me too! Are you Christian or Buddhist?"
"Christian."
I said, "Me too! Are you Catholic or Protestant?"
"Protestant."
I said "Me too! Are you Episcopalian or Baptist?"
"Baptist."
I said, "Me too! Are you original Baptist Church of God, or are you Reformed Baptist Church of God?"
"Reformed Baptist Church of God."
I said, "Me too! Are you Reformed Baptist Church of God, Reformation of 1879, or Reformed Baptist Church of God, Reformation of 1915?"
He said, "Reformed Baptist Church of God, Reformation of 1915."I said, "DIE. HERETIC SCUM!" and I pushed him off.
The analogy is quite good. Whether it is coding standards or matters of religion, there is an objective truth.
Different people can believe different things about how to lay out code. But in every case the result will depend on how you do it. I used to write many functions all on one line, until I realized it actually caused me to make a lot of mistakes. Some layouts are objectively more readable than others; some are more error prone.
The same is true of religion. There is one objective truth, and what you believe will affect the eventual outcome.
You have to be quite similar to someone to _really_ hate them. I’m sure the leninists and trotskyites hated each other far more than they hated the nazis.
Anyway, the only reason to write the ugly:
while ( true ) {
…
}
Instead of the much clearer ‘one true way’:
while ( true )
{
…
}
Is to save space in books. Anyone who says otherwise must be purged.
I think a lot of confusion coming from the question ‘What is better?’. To my mind coding standards are not designed to solve that problem. I strongly believe that the major reason to have one coding standard and follow it is to make the code maintainable. Everybody have their own style and which one is better doesn’t truly matter. What matters is an ability for you to get to the piece of code that you didn’t write and still figure out in the shortest time period possible what’s going on there and adjust it to the current requirements…
We all following the rules of roads not because they are convenient to follow or because they fit our style, but merely because following rules of roads will get you to your destination faster and safer(most of the times)… Sometimes, sure enough, we break them to cut the corners 🙂