What makes code "readable"? (was Re: Python vs. Perl, which is better to learn?)

James J. Besemer jb at cascade-sys.com
Wed May 8 01:04:43 EDT 2002


Christopher Browne wrote:

> I'll often use quite horridly short names, initially; it's easy enough
> to do a search and replace to fix that.  That mandates having the
> _discipline_ to do so...

I submit that in some cases short names are quite appropriate.  E.g., for simple
loop indices or function arguments:

    for i in xrange(N):
        ...

and

    def convert( s ):
        return hex( s.strip())


However, for short names to be appropriate, the useage needs to be simple and
very local in scope.  (Of course where to draw the line is a judgement call).

Even in simple cases, more specific word choices can be helpful:

    for item in list:    ...

    for key in dict:    ...

    for pair in PairList: ...

And it always pays for any more prominent names in your program to be carefully
chosen.

Regards

--jb

--
James J. Besemer  503-280-0838 voice
http://cascade-sys.com  503-280-0375 fax
mailto:jb at cascade-sys.com







More information about the Python-list mailing list