A notch above a monkey » Whitespace whining

Whitespace whining

Ian Bicking’s wrote a list of python wishes. There’s stuff I agree with, some with which I don’t and stuff I simply don’t understand. But what caught my eye was:

Things I wouldn’t do:
Put up with any significant-whitespace whining. Here 99% of the Python community is with me. I think there is a meme that Python people are close-minded to suggestions for changes in the language. I think there is significant truth to that. But sometimes everyone else is just completely wrong. 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 absurd.

Precisely. Yesterday was our regular web talk evening, which is often followed by a lively debate. As usual we covered all sorts of topics, one of which was Python. To paraphrase a part of it:

A: I don’t like Python because of significant whitespace.
B: Do you indent your code?
A: Yes, of course.
B: And the problem is?

I can’t understand how this complaint doesn’t die. I can understand that some other language can tickle their fancy. People have different tastes and if some people like it rough, who am I to judge. But why in the world would you wish for a feature you’d never be stupid enough to use?

Comments (16)

  1. Hey – that’s the shortest, most succinct and coolest way I have ever seen it written – 4 short lines of text spell out Python Whitespace clearly :-)

    Comment by Mark Mc Mahon — #
  2. I wish all languages would have Python’s whitespace policy

    Comment by david #
  3. I explain to my naysaying peers that whitespace is a defining feature of Python, just like dynamic typing (which generates it’s own series of whines in my group).

    I then suggest that if you do not like it, use a language that fullfills you needs, rather than griping about one that does not.

    After all, what it the point of duplicating features already found in other languages? Not everything can be (C,Java,VB).

    Comment by Matt — #
  4. I like Python whitespacing, but one legitimate gripe with it involves hard-to-find cut-and-paste bugs. More than once, I have cut-and-paste Python code that I’ve found on a web page, only to have it not run because the indenting got screwed up in an inconsistent and subtle way that’s hard to immediately identify.

    But it’s a niggling point, and it’s not what people usually mean when they give the knee-jerk “I don’t like significant whitespace” response.

    Comment by Matt — #
  5. Matt: it is indeed a niggling point. There are many reasons why code cut-and-pasted from a website might not run accurately. If failure due to incorrect indentation causes the lifter to stop and think about the code it’s not entirely a bad thing.

    Far too much copy-and-paste “programming with a trowel” is already taking place. If people aren’t prepared to at least *think* about the code they are “borrowing”, they shouldn’t be “borrowing” in the first place.

  6. I’ve had problems caused by people editing files in editors that did things like use the tab character – it looks like the indentation is correct but in fact it is not. When these happen, it is very difficult to recover the correct control flow because of python’s reliance on whitespace. Whilst it is not a big enough issue to stop me using python, I do regard it as a language design flaw, and it does cause me real world problems.

    Comment by Richard Moore — #
  7. :”I’ve had problems caused by people editing files in editors that did things like use the tab character – it looks like the indentation is correct but in fact it is not.”

    That is an editor flaw, not a language flaw. You need an editor that you can configure to handle tabs properly for the task at hand. The right tool for the right job.

    Comment by mksql — #
  8. (a) tabs are evil

    (b) indentation errors are usually pretty easy to find, but sometimes rather hard to fix if you’ve lost the original indentation; on the whole significant whitespace leads to much easier to understand syntax errors, that are more localized to the actual problem area of code

    (c) there is a small class of errors that is admittedly really annoying — typically when you have an if statement, and the last line of the block is either mis-included or mis-excluded from the block; the only way to figure it out is through careful inspection of the logic. This can happen in any language, but is more common in Python (a similar class of errors is in Cish languages when people don’t use {} for the body of an if or other block — which is also probably the quintessential case when programmers make indentation that lies).

  9. I like tabs :)

    In any case, there’s a plethora of editors that make indenting, de-indenting and tab-space transformations a breeze and if anyone still has a problem with this, he should really switch to something better than notepad.

    I guess those (c) errors can be annoying, but I think you get a similar problem in other languages when you copy one } too much or too few. Admitedly not quite the same, because Python’s case is more subtle, since it’s likely not a syntax error. I don’t copy blocks often or fast enough to be bothered though.

    Comment by markos #
  10. I wasn’t sure about significant whitespace when I started using Python.

    Now I love it, because it makes removes unnessary garbage such as:

    But, it can be a disadvantage if you’re doing serious metaprogramming, by making creating error free Python code considerably harder. That’s one big reason, for example, why Lua uses begin/end.

    But Python isn’t about heavy metaprogramming. OTOH, Lua uses much more metaprogramming, and it’s also a much bigger part of its culture.

    In summary, significant white space is great in Python, but not in all programming languages.

    Comment by TonySV — #
  11. For what it’s worth, here’s a testimony: when I first got interested in Python – at first, reading about it – I liked it very much, but I saw significant whitespace as its major drawback and a pain in the neck. It was, like, “what a ridiculous, absurd feature in an otherwise great language”. Then I started coding in it, and there wasn’t even an adaptation period – I didn’t as much as _notice_ that I was using the feature, once I concentrated on problems. Whitespace is simply NO problem, and code readability is a major gain. Just as Ian says, let’s not accept any whining in this area.

    Comment by Grzegorz Staniak — #
  12. Far more irritating to me, than whitespace errors when copying code, is non-standard characters appearing in code snippets in emails and web pages, usually because they are written in a word procesor that silently ‘helps-out’ by changing one tick to a back-tick so destroying what should be a pair of string delimeters (or doing a similar thing with doule-quotes).

    Pythons whitespace indentation will be brilliant when you are no-longer allowed to use tabs ;-) and is pretty damn good as it stands.

    Comment by paddy #
  13. I’ve been coding in python for a decade now and I always use tabs in my own projects. I have never once had a tab/space issue. This leads me to following belief: if you have problems with tabs you are an idiot.

    Comment by Justus #
  14. “Things I wouldn’t do: Put up with any significant-whitespace whining. Here 99% of the Python community is with me. Precisely.”

    All he said, and you agreed with, was that 99% of the people who like Python’s white space, and hence use it, agree with it. I fail to see the significance.

    What about the majority of programmers who won’t give Python a try because of the white space issue? You can claim that popularity is not the goal but, oh, how the Python community moans when Ruby on Rails is mentioned.

    It’s not like Python currently offers one correct solution to delimiting scope. It currently offers three: spaces, tabs or spaces and tabs mixed together. You might like one of these but I bet you’ll agree the other two stink. So… how about adding one more stinky optional method for delimiting scope: braces. Is that too much to ask for if it could help Python reach Ruby’s level of popularity and acceptance in the ($$$) workplace??

    FWIW, I like tabs.

    Comment by John Mudd — #
  15. Actually, I like tabs, but don’t mind either. I use tabs, but I also worked with spaces-only and mixed indented code and honestly can’t remember when was the last time I had a problem related to this. My view is that this simply isn’t an issue.

    I also don’t mind RoR. I do mind marketing-driven features though. What I’d like for Python is to avoid adding features that don’t significantly improve a language for its current users and I fail to see how braces would do this.

    I might look at this differentely if Python acceptance was a problem for me, but luckily it isn’t.

    Comment by markos #

Sorry, the comment form is closed at this time.