Python paradigms

Grant Edwards grant at nowhere.
Mon Apr 10 16:29:35 CEST 2000


In article <38F1C600.3FD9878B at acm.org>, Robert W. Cunningham wrote:
>
>> |> > So, it works just fine, right?
>> |>
>> |>    No. Code is intended not only to beeing run on processor, but also (and
>> |> often more important) to beeing read by human. Code is speech, it is the
>> |> way to interchange ideas.
>> |>    In that sense ugly code is not working even if you add three books of
>> |> comments. Code should be readable. Period.
>>
>> Yes, precisely.  In the real world, programs often have long
>> lifetimes, are worked on by many programmers (in parallel and
>> sequentially), are sometimes transliterated between languages,
>> and it is common to need to modify code which was written 20
>> years ago by some long-retired programmer.
>>
>> At best, confusing code wastes effort.  At worst, it causes
>> mistakes to be introduced.  I have seen the latter effect many
>> times.

>Again, comments in the code can cover all these bases.  

Not in my experience.  There's one problem with comments:
They're wrong.  Either a) they never matched the code, or b)
somebody changed the code and forgot to fix the comments.

On the legacy stuff I've worked on what the comments say rarely
matches what the code does.  Perhaps you're experience with the
veracity of comments is better than mine, but after 20 years of
working on other people's (and my) old code, I've learned one
thing the hard way:

**Ignore the comments.  They're misleading more often than not.**

Sometimes I fix the comments, usually I just delete them.  A
sentance or two to describe what a function is to be used for
is about the only useful comment I have run into (the "doc"
strings for example).  Comments on individual variables and
lines of code are usually worse than useless.

In assembly comments are probably required, but in a language
like Python, if code needs comments other than the occasionaly
"doc" string, then it's written badly.

-- 
Grant Edwards                   grante             Yow!  Did YOU find a
                                  at               DIGITAL WATCH in YOUR box
                               visi.com            of VELVEETA?



More information about the Python-list mailing list