A Brief Defense of Significant Whitespace
In my Python 4K post
I want nothing to do with any programmer who would mis-indent
their code. If you want to mis-indent your code you are an
idiot. If you want idiotic code to be an option you are being
This might come off as a little... well, not a friendly way of saying
it. Maybe I'll expand a little:
- We all know what "correct" indentation is. Really, all of us, from every
- Python enforces only correct indentation (though still with a
certain amount of flexibility). The only hitch is with multi-line
statements. Yet the newline as a statement terminator doesn't seem
controversial. Go figure.
- So, Python is enforcing the bare minimum of style. By "bare minimum" I
mean that level of style that even you will curse yourself for not
and a level of style that if you don't conform to will cause revulsion for
anyone else who sees your code.
- It's not that hard to indent your code properly. Indenting
improperly is not a big time saver, even for one-off scripts. Some
people say "one-off scripts usually aren't". But you don't have to
say that -- even for really truly one-off scripts indenting is not
- Coming up with stories where it is better not to indent your code
properly is the "absurd" part. It's just not worth it, and I
honestly don't believe anyone rationally argues otherwise.
- Admittedly, people argue it irrationally. I think they feel Python
is being paternalistic, and they don't like that; it invokes an
emotional response. I think that is doubly irrational, because
there's all sorts of other things Python requires that people don't
worry about -- like case sensitivity -- simply because programmers
are already used to those things. Why the concern over something even
less controversial than case issues?
- Significant whitespace leads to very readable syntax errors.
(Newline terminators also do this, as does = as a statement, and
some other syntactic details.)
- It really helps programming flow that most all syntax errors in Python are
trivial to detect (at least for an experienced programmer -- but you
don't have to be experienced in Python to understand syntax errors
quickly, you just have to be experienced in any Algolish language).
- Do you really have no memory of how obnoxious some other languages
can be about syntax errors? Like, really really obnoxious? It's
not worth it, especially when the syntax errors are less helpful because
of a complete non-feature like insignificant whitespace.
Update: I really messed something up and everyone who submitted comments
had them sent into the void. What baffles me is that people then replied to
the empty comments...? Anyway, sorry about that; fixed now.
Created 08 Mar '06
Modified 08 Mar '06
"What baffles me is that people then replied to the empty comments...?"
Is is a whitespace discussion after all ;)