Python indentation deters newbies?

Antoon Pardon apardon at forel.vub.ac.be
Tue Aug 17 08:22:30 EDT 2004


Op 2004-08-17, Sibylle Koczian schreef <Sibylle.Koczian at Bibliothek.Uni-Augsburg.de>:
> Porky Pig Jr schrieb:
>> beliavsky at aol.com wrote in message news:<3064b51d.0408130615.3fc4a760 at posting.google.com>...
>> 
>>>One of the most commmon reasons programmers cite for not trying Python
>>>is that indentation determines the program flow -- they think its
>>>weird. I think programmers who actually try Python adapt quickly and
>>>do not find the indentation rules to be a problem.
>>>
>> 
>> 
>> Not only it's *not a problem*. I've found it quite useful since it
>> forces you to keep the proper indentation.
>> 
> I think indentation that's only there for human eyes, not for the 
> compiler, can be the reason why you overlook your bugs:
>
> First version:
>
> if (condition) then
>      statement-1;
> statement-2;
> ...
>
> Second version:
>
> if (condition) then
>      statement-1;
>      statement-1a;
> statement-2;
> ...
>
> This isn't Python but Pascal, but you probably wanted the compiler to do 
> exactly what Python _will_ do: execute statement-1a if (and only if) 
> condition is true. I've done this time and again and each time wondered 
> about incorrect results.
>
> Of course this won't happen if you have to use braces or begin - end 
> even for a single statement. But with Pascal or C/C++ that's not enforced.

That is why I prefer modula2 style.

> And those staircases of
>
>          end
>      end
> end
>
> (quite a short example) aren't really beautiful, or are they?


Maybe not, but they do help readability in a whole lot of
cases.

-- 
Antoon Pardon



More information about the Python-list mailing list