Many people, upon first seeing Python's use of whitespace, have a negative reaction. This is mostly because of the mantra that "FORTRAN had significant whitespace, and that was a big pain."

Refutation:

  1. Even the significant whitespace in FORTRAN wouldn't have been so bad if programmers had been using colorizing editors back in the day. If the comment field were one color, the label field another, the continuation field a 3rd... Few errors mistaking one field for another would've struck.
  2. When programmers scribble pseudocode on a whiteboard, they indent, but they rarely use curly braces or begin/end or do/od or whatever. Why? Because indentation alone is quite sufficient for rapid communication.
  3. It's harder (or was) to find a missing pair of curly braces than bad indentation
  4. Please note that I've written this HTML document using significant whitespace; you know what it means, most likely. Curly braces really wouldn't clarify things.
  5. Too little significant whitespace can also be a problem:
  6. Other languages with significant whitespace:
  7. At times the complaint about significant whitespace comes from people who use Really Long Functions or MethodsTM. You've probably already guessed that Really Long Functions or Methods are best avoided. Also, you can use a folding text editor to deal with them more effectively than curly braces could.
  8. This one, I can only partially refute. If you're automatically generating Python code, the indentation is sometimes a true pain, not just an excuse. However, an important class of automatically generated code is intended to be human readable; this code should be indented anyway. But automatically generated python code that's not intended to be human readable is an issue, and isn't exactly an achilles heel.
  9. Another I can only partially refute: If you're having an e-mail discussion about code, some mailers like to reformat your code into a paragraph. Needless to say, this is bad for pretty much all code, but pathological for Python and other languages that use whitespace in a manner distinct from basic paragraph-filling.

    Some alternatives:




Hits: 6753
Timestamp: 2024-12-27 08:47:01 PST

Back to Dan's tech tidbits

You can e-mail the author with questions or comments: