Python indentation deters newbies?
Sibylle Koczian
Sibylle.Koczian at Bibliothek.Uni-Augsburg.de
Tue Aug 17 04:19:27 EDT 2004
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.
And those staircases of
end
end
end
(quite a short example) aren't really beautiful, or are they?
Koczian
More information about the Python-list
mailing list