Re: Another request for comments on beginner code

Guido.van.Rossum@cwi.nl
Sat, 05 Mar 1994 11:42:50 +0100

Great reply... though my taste for loops is always

while 1:
line = psfile.readline()
if not line: break
...

rather than your

line = psfile.readline()
while line:
...
line = psfile.readline()

If you're ever going to change the way you get the next line, you're
less likely to forget that you have to modify *two* identical
statements. I'll happily accept the redundant test in "while 1:".
Also I don't think that binding psfile.readline to getline will save
much given that there is real I/O as well as other processing going on
as well; a simple name lookup can't cost *that* much...

Next, I would write the whole think as a function:

def main():
<original program, indented one more tab stop>

main()

This gives you the optimization for local variables.

And finally I'd use another name than "string" for the command to be
executed since it is also the name of a standard library module --
maybe in version 4.3.7 of the program (by then 200 lines :-) there'll
be an unexpected need to import that module and some confusion when
the two names clash...

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>