[Edu-sig] Learning to Program comments

Scott David Daniels Scott.Daniels at Acm.Org
Mon Nov 8 16:20:16 CET 2004


"Looping - Or the art of repeating oneself / More about the Python _for_ 
construct "

Guido has said that single-line ifs and loops are one of his regrets.
The temptation to use the is great, and the problem is, that in
isolation they look clear.  White space is not that expensive
(esp on a computer screen).  Since my code does seem to want to cramp
up myself, I force myself to pretend that a colon ends the line (except
for comments).  I'd suggest you might break even your single-line loops
into two lines.  First, it makes it easier distinguish the sequence
from the repeated statement:

     >>> for word in ('one','word', 'after', 'another'):
     ...     print word
     ...

vs.

     >>> for word in ('one','word', 'after', 'another'): print word
     ...

These are not to tough to piece out, but seeing the trailing comma
in the following example and distinguishing it from the construct
visually is much easier when you are looking at

     ...     print word
vs.
     ...     print word,



As I hope I've said before, I am not dead certain I'm right, but I'm
hoping you'd like to have the comments to apply or ignore as you
see fit.

-- Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Edu-sig mailing list