Python indentation deters newbies?

Porky Pig Jr porky_pig_jr at my-deja.com
Sun Aug 15 06:04:29 CEST 2004


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.

Granted, the very first time I read about this feature, I've thought:
what a funny thing -- but then I've realized that since I keep the
proper indentation anyway, Python simply eliminates 'parenthetical
clutter' (in addition of forcing you to keep the code nicely
alligned).

For instance, in C I write

if (condition) {
    statement-1
    statement-2
}
else {
    statement-3
    statement-4
}

or some other coders prefer to write

if (condition) {
    statement-1
    statement-2
} else {
    statement-3
    statement-4
}

but in Python all those extra parenths are gone, and code is more
compact, more easily observable. you can squeeze more code into a
single displayble area which *is* important.

On the other hand, C has nothing that prevents someone from writing
the code:

if (condition) {
statement-1
statement-2 }
else {
statement-3
statement-4
}

Just had the situation a few weeks ago when novice C++ programmer
asked for help. Even if that programmer used emacs, somehow she has
managed to write the code as above. I simply told her to get her
identation in place first and then get back to me.

So: if you are a programmer who - as a matter of habit - writes nice
properly indented code, you will quickly appreciate the advantages of
Python (just like I did), and if you don't -- well, that's too bad.



More information about the Python-list mailing list