What makes code "readable"?

Philip Swartzleonard starx at pacbell.net
Wed May 8 07:39:39 EDT 2002


Terry Hancock || Tue 07 May 2002 02:49:48p:

> I frequently use shorter variable names in loops and other
> local scopes as mentioned above -- sometimes I think this
> can make things clearer or avoid errors. I recently had some
> code that looked like this:
> 
> for view in views:
>      ...
> 
> This kind of bugs me because I always feel like I'm going
> to leave out the 's' and get obnoxious bugs (more honestly,
> I've gotten bitten by it enough to think that). So I
> changed it to:
> 
> for vw in views:
>      ...
> 
> (Which I still say the same way, but this makes it harder
> to confuse, I think).  I'm still waffling over it,
> though -- which do you think is better?  Maybe I should
> say 'viewtachi' and 'view', heh. ;-)  (Yes, I'm kidding).

Hm, maybe it's just me being rather more attuned to (written) english 
than average (as far as i can tell...), but I'd never have a problem 
with that. View and Views are just unmistakably diffrent to me. With a 
word with lots of s's in it maybe, but... hm...

Anyway, wou could also use 'viewra' instead of 'viewtachi', it's a bit 
more typeable. Just then hope you never get variables named 'amon' or 
'mumm' =)
 
> I often have some confusion over whether to use plural
> names -- it bothers me to name a list, say 'myfiles',
> and then refer to an element as 'myfiles[2]' or something.
> Of course, in Python you don't have to do indexing
> like this as much (because of loop constructs like those
> above), so maybe it's not so important (and maybe I
> ought to return to the view/views instead of vw/views?).
> 
> Anyway, I don't think just having long or even long
> pronounceable names is necessarily good -- it's got
> to be meaningful to the programmer.  I'm not going to
> be quick to forgive the Zope developer who came up
> with 'bobobase_modification_time'. :-D I mean, sure,
> after some time working with it and reading the history,
> I've learned why it should be called that, but I'd still
> have been happier with 'obj_mod_time' or something.
 
There's style, and then there's fitting the damn thing in an expression 
on a line in a for loop in an if statement in a function in a class 
while using (iiick) 8-space tabs ;). Yes, i'm quite guilty of making 
names too long, at least initially. Good examples: my most horrid python 
module... sxrandom:

        name += gennamesec( nameparts, pickpercentdic(lastnamesylpd) )

Er... don't ask. I wasn't even using underscores there for some reason. 
This is a wad of code i never ever want to look at again. A better 
example would be 'percentage_chance()'... it just sounds better as 
'perchance()' anyway =). This is a handy little thing where:

if perchance(75): print "Executes 75% of the time"

It's real nice for e.g. random-filling test mazes.

Um... did i have another point down here? Oh well, bedtime.

-- 
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



More information about the Python-list mailing list