[Tutor] 2 & 4 or more spaces per indentation level..

Senthil Kumaran orsenthil at gmail.com
Fri Jan 16 04:41:06 CET 2009


On Thu, Jan 15, 2009 at 06:57:09PM -0700, Eric Dorsey wrote:
>    Working in IDLE on Windows Vista, I have one program that I set to have
>    2 character spacing (due to the levels of if's and while's going on --
>    later my brother called this a bit of a code smell, ie. logic shouldn't
>    go that deep, it should be broken out into separate functions instead.

Your brother is right. Logic should not go deep and moreover the
screen width not enough even with 2 space indentation gives a
not-so-good picture too.

>    Thoughts on that are welcome to, do any of you feel logic should only
>    go so many layers deep?), and my editor defaults to 4 (Which I believe
>    is the standard according to PEP 8)

Thats the way to approach. Follow PEP8.

>    they used a different spacing than you, is there a simple/good/smart
>    way to get it all back to the 4 spacing default? Or if for example I

Rule #0 is Never mix tabs and spaces.
Rule #1 is use a standard spacing through out the code.

And when copying from a certain space-setting indentation to another,
the modular script will still work fine. You can use some global
find/replace mechanism to do suit your setting.
For eg. I remember doing :%s/\ \ /\ \ \ \ /g

OR you can also run your code through pyindent or python code
beautifier (Google for it, you might find one). But after using the
beautifier under these situations, just rely on your eyes to do a
quick check if the logic has not gone awry ( which rarely does, but
still I would believe myself more than the tool).

-- 
Senthil

http://uthocode.sarovar.org 


More information about the Tutor mailing list