[Tutor] Variable declaration

Wayne Werner waynejwerner at gmail.com
Fri Feb 5 19:09:15 CET 2010


On Fri, Feb 5, 2010 at 10:40 AM, Hansen, Mike <Mike.Hansen at atmel.com> wrote:

> Perl has "use strict;" to force variable declaration.
>
> My insane Perl loving co-workers think it's evil that Python doesn't have
> variable declaration. =)
>
> What are some of the reasons/arguments on why Python doesn't need variable
> declaration? I've gotten around it in Python by using Pyflakes to check my
> code and catch those silly mis-spelling of a variable.


I've never had any serious problems (though I've never worked on huge
projects with Python), but here are some of the reasons that pop into my
mind:

1) We're big boys and girls - we're responsible enough to pay attention to
our variables

2) I have no clue, but it may make it easier on the garbage collection -
once a value/object no longer has a reference it can probably be cleared up.
But those c variables you declared way back in the beginning of your
program? Still there (though an anti-argument would be that you're not using
scope properly in this case)

3) If you're writing a small program you should be able to see everything,
but if you're using a big enough program you should be using an IDE that
keeps track of that sort of thing.

I don't know how valid those reasons would be considered... but I, for one,
like the freedom of not having to type:

int a = 0;

or

int a;

MyClass(){
    a = 0;
}

or any other waste of keystrokes. If I want a new variable, I'll make it
responsibly - whether I need it here or there...

but that's my two cents
-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100205/3ffcd7a6/attachment.htm>


More information about the Tutor mailing list