Please Critique

John Farrell jfarrell at mincom.com
Tue Dec 14 20:01:20 EST 1999


Klaus Baldermann wrote:
> John Farrell wrote in message <3855DB3D.998F3081 at mincom.com>...
> >>     while start < length:
> >>         end = start + 4
> >>         startkey = start + 1
> >>         mydict[trimline[startkey:end]] = trimline[start:end]
> >>         start = end
> 
> >    while len(line) >= 4:
> >        instruction = line[0]
> >        number = line[1:4]
> >        line = line[4:]
> >        mydict[number] = instruction
> 
> This could be even more perlified:
> 
>     while len(line) >= 4:
>         mydict.update({line[1:4]: line[0]})
>         line = line[4:]

Isn't perlification bad? I realised I could cut down on lines, but given
that one of the comments on the original code was that it needed more
comments, I decided to write for readability rather than perlicity.

On the subject of comments, Kernighan and Plauger wrote: "Do not comment
bad code, rewrite it." That is not to say that the original code was bad,
just that adding comments is usually not the best solution. See discussion
at:

http://www.c2.com/cgi/wiki?TreatCommentsWithSuspicion

John
-- 
Dr John Farrell - Research Architect - Mincom Limited

This transmission is for the intended addressee only and is confidential
information. If you have received this transmission in error, please delete
it and notify the sender. The contents of this E-mail are the opinion of the
writer only and are not endorsed by Mincom Limited unless expressly stated
otherwise.
----
I don't suffer from stress.  I am a carrier.




More information about the Python-list mailing list