variable declaration
Roy Smith
roy at panix.com
Sat Feb 5 08:31:22 EST 2005
In article <MSGID_2=3A5025=2F3.131_4204c40a at fidonet.org>,
Alexander_Zatvornitskiy at p131.f3.n5025.z2.fidonet.org (Alexander
Zatvornitskiy) wrote:
> And, one more question: do you think code like this:
>
> var S=0
> var eps
>
> for eps in xrange(10):
> S=S+ups
>
> is very bad? Please explain your answer:)
Let me answer that by way of counter-example.
Yesterday I was writing a little perl script. I always use "use strict" in
perl, which forces me to declare my variables. Unfortunately, my code was
giving me the wrong answer, even though the interpreter wasn't giving me
any error messages.
After a while of head-scratching, it turned out that I had written "$sum{x}
+= $y" instead of "$sum{$x} += $y". The need to declare variables didn't
find the problem. I *still* needed to test my work. Given that I needed
to write tests anyway, the crutch of having to declare my variables really
didn't do me any good.
More information about the Python-list
mailing list