why no "do : until"?
scarblac at pino.selwerd.nl
Sun Dec 31 06:58:19 EST 2000
Steve Lamb <grey at despair.rpglink.com> wrote in comp.lang.python:
> On Sat, 30 Dec 2000 23:00:53 GMT, Kragen Sitaker <kragen at dnaco.net> wrote:
> >Hahaha! You just plonked Fredrik Lundh in comp.lang.python. He was
> >being helpful and polite, and you plonked him because you disagreed
> >with him. I can guess how much help you'll get next time you have a
> >Python question. :)
> I can tell you I'll get far better without him than with him when he is
> giving advice that runs contrary to about 10+ years of programming that I've
> been taught from various different sources.
"I don't care if he's one of the few best posters ever on this newsgroup.
He's saying something I don't want to hear!! *plonk*".
> I don't care if he is God
> himself, advocating not initing a variable is stupid, plain and simple.
Nothing is ever as simple as that. You're giving that variable two different
meanings - first you use it as a flag that lets you enter the loop, then
you use it to store a temperature in. Yes, you initialize it, but you're
not initializing temperature! You are like those people who
"#define THIRTEEN 13" because they should #define all the constants they
use in their program.
One clue - if the guard of the loop ever changes,
you might need to change your initialization - that's an alarm bell. The
initial temperature didn't change, did it? If you need both a flag and
a temperature, use two variables.
> wanted to argue the point for nothing more than argument's sake, so be it. I
> don't need his advice any further.
You're applying some rule just for the rule's sake.
A mother was teacher her child to prepare a big meat dish, the way she had
done it for 20 years, and that her mother taught her. She explained which
spices to use, how to prepare the meat, and then two cut off two bits from
the sides and put it in the pan. The daughter was puzzled by this. "Why do
you cut off the sides?" "That's the way it's done. It's better. My mother
taught me, and doing it any other way is just plain stupid." The daughter
wasn't quite convinced, and asked her grandmother some other day. "Well, I
don't know why *she* does it, but I did it because my pan wasn't big
The normal reason for always initializing a variable in many languages is
that their value might be undefined (random) otherwise. Not so in Python. In
Python, using an uninitialized variable will fail loudly, meaning you have a
control flow bug, most likely. Initializing variables when you don't need to
hides bugs. Don't simply apply rules.
More information about the Python-list