[Tutor] Python Best Practice/Style Guide question

Alan Gauld alan.gauld at btinternet.com
Tue Apr 29 23:02:50 CEST 2008


"W W" <srilyk at gmail.com> wrote

> Even with monospace, I can't really see it being that helpful, after 
> all, in:
>
> x = 3
> y = 5
> foobar_fun = 20
>
> 3 and 5 are in no way related, x and 3 are. However, sometimes I 
> break
> them up into more beautiful chunks:

In Python it doesn't make much difference but in C and other similar
languages it helps a lot to line up assignments as the OP did because
you can scan a list ov variables and see which ones have not been
initialised before use. And uninitialised variables are probably the
biggest single cause of bugs in C programs so the experienced
C maintainer will go straight to the variable lists before doing 
anything
else with a file. And if they are neatly lined up a blank line stands 
out
like a sore thumb. (In fact the act of lining them up will often 
prompt
a lazy developer to initialise variables himself, just to tidy things 
up!)

But in Python where variables are created by assignment the
concept of an unitialised variable dioesn't make sense. And
because Python has garbage collection unitialised/non-freed
pointers don't cause problems either... :-)

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld





More information about the Tutor mailing list