Python and Ruby

Steven D'Aprano steven at
Mon Feb 1 02:33:26 CET 2010

On Sun, 31 Jan 2010 18:47:42 -0600, John Bokma wrote:

> Steven D'Aprano <steve at> writes:
>> On Sun, 31 Jan 2010 14:47:08 -0600, John Bokma wrote:
>>> An editor can correct the indenting of the braces example but can't
>>> with this one.
>>>   if x:
>>>       if y:
>>>          foo()
>>>   else:
>>>       bar()
>>> While braces might be considered redundant they are not when for one
>>> reason or another formatting is lost or done incorrectly.
>> I've heard this argument before, and I don't buy it. Why should we
>> expect the editor to correct malformed code?
> Or a prettyfier. It doesn't matter. The point is that with braces there
> *is* redundancy that be used to fix the code.

Prettyfiers are significant in languages that allow braces (or begin/end 
tokens) and indentation to go out of sync. Since that can't happen with 
Python, it's not a problem that needs solving. Prettyfiers exist to work 
around a limitation of languages where indentation is not significant.

Arguing that an advantage of braces is that prettyfiers can work with 
them easily is a silly argument. That's like saying an advantage of horse-
drawn buggies over cars is that it will go faster when you hit the horse 
with a whip. That's true, but you only need the whip because of the lack 
of accelerator pedal.

A much better argument would be that an advantage of significant 
indentation is that you no longer need a prettyfier, and a second 
advantage is a major reduction in flame wars over coding styles.

>> Would you expect your editor to correct this malformed code?
>> result = sin(x+)y
> Nice straw man.

It's not a straw man. It's a serious argument. There is an infinite 
number of problems with malformed code that your editor can't fix, and 
your prettifier can't deal with. Why should we care if indentation is one 

There are tools out there (such as some web forum software) that corrupt 
whitespace. Those tools are broken, and if you (generic you), as a 
developer, are relying on those tools to code with, then shame on you. 
And if you're the creator of such broken tools, then shame on you more. 
You wouldn't arbitrarily decide to remove leading "E"s from the user's 
text, or trailing full stops, so why do you arbitrarily remove whitespace?

> Let me repeat again: I am ok with how Python works. To be honest I think
> it's cleaner compared to using {}. But in there are real life examples
> in which Python code will break where code with braces will survive.

Yes. So what? They are rare and insignificant in practice. For every line 
of code that you get via a webforum that mangles indentation, you get ten 
thousand lines of code from some place that doesn't.

So long as code is written by and for human beings, the benefit of 
significant indentation is 100% practical, and the practical benefit of 
braces will remain insignificant.


More information about the Python-list mailing list