variable declaration

Antoon Pardon apardon at forel.vub.ac.be
Mon Feb 7 08:28:04 EST 2005


Op 2005-02-05, Roy Smith schreef <roy at panix.com>:
> 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.

I you come to the conclusion that it doesn't do you any good, why did
you use it? I find it odd that someone who prefers to use it in a
language where it is optional is argues that it shouldn't be included
as an option is an other language. I would think that if he thinks
it so bad he wouldn't use it in that other language in the first place.

-- 
Antoon Pardon



More information about the Python-list mailing list