Style question...

Chad Netzer cnetzer at sonic.net
Wed Aug 27 22:38:31 EDT 2003


On Wed, 2003-08-27 at 19:06, Erik Max Francis wrote:
> Anthony Roberts wrote:
> 
> > There is, but it can't tell if I want some stuff indented or not.
> 
> Sure it can.  Hit tab or backspace.

I think the problem is that people learn to reindent chunks of code by
the following technique:

<arrow down>
<TAB>
<arrow down>
<TAB>
.
.
.


This has the unfortunate consequence of breaking your code when you hit
multiply indented loops, nested functions, function or loop boundaries,
etc.

However, by sticking 'pass' at the end of loops, emacs's python-mode
will assume a dedent and preserve the indenting at boundaries.

But, this technique will STILL fail on multiply nested loops, etc.
(emacs does it's best, but it cannot mind read)  So it is a terrible
habit to get into, because it WILL cause you problems if relied upon
blindly.

So, it is better to NOT rely on the 'pass' crutch, and instead rely on
the python mode operations for reindenting blocks of code (which Eric
provided; surely this is becoming a FAQ)

So, to Anthony, if you are using the TAB key to indent blocks of code,
and relying on 'pass' to make it easier, just be aware that this
technique is NOT robust.

-- 
Chad Netzer <cnetzer at sonic.net>






More information about the Python-list mailing list