variable inirialization and loop forms (was Re: why no "do : until"?)

Peter Hansen peter at engcorp.com
Sat Jan 6 02:15:11 EST 2001


Lloyd Sommerer wrote:
> 
> While I'm just learning Python, I was wondering if anyone knows a good reason
> not to express a loop in this manner:
> 
> T = getCurrentTemperature()
> while warmEnough(T):
>     T = getCurrentTemperature()
> 
> This is expressed in Alex's generalization, but I think also applies to the
> original code:
 [snip]

> I realize that written this way there is a maintainability issue. Perhaps that's
> reason enough not to do it this way.

Yes!  That is definitely reason enough not to do it this way.  
The moment I catch myself writing lines that are that clearly 
redundant that close together, I refactor to remove the
redundancy.  

Maintenance issues are, in my opinion, one of the
most under-appreciated problems of software development.  All
code has to be maintained, even if it's just by the author,
and even if it's just a day after the code was written.  The
likelihood (as shown by direct experience and long observation)
of code like the above being broken by subsequent changes
being made incorrectly is much higher than if the code were
written without the duplicate lines.



More information about the Python-list mailing list