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

Alex Martelli aleaxit at yahoo.com
Sat Jan 6 05:11:17 EST 2001


"Peter Hansen" <peter at engcorp.com> wrote in message
news:3A56C5FF.DA0C8BD8 at engcorp.com...
    [snip]
> > T = getCurrentTemperature()
> > while warmEnough(T):
> >     T = getCurrentTemperature()
> >
> > This is expressed in Alex's generalization, but I think also applies to
the
    [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.

VERY right!  "Doing each thing *once*" is a good guideline.

> Maintenance issues are, in my opinion, one of the
> most under-appreciated problems of software development.  All

...except by actual practising programmers -- having spent
over 50% of one's time maintaining for a few years can be
a good eye-opener:-).

> 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.

Bears repeating, as it's so *intensely* true!-)

It's not as terrible here, because the getCurrentTemperature
function encapsulates whatever is being done for the purpose;
most cases you see such repetitious style, the author has not
bothered encapsulating, so 2 or more statements, or a complex
expression at least, are being repeated.  Still, it's even better
to avoid the repetition altogether, if feasible.


Alex






More information about the Python-list mailing list