declaration of variables?
Carl Banks
imbosol-1045437390 at aerojockey.com
Sun Feb 16 18:28:56 EST 2003
Brian Quinlan wrote:
> > And I do think that declaring a variable isn't that much of a hassle,
>> atleast not of the magnitude you (and others) make it out to be.
>> Chasing down "strange" errors is.
>
> Declaring variables in Python would severely reduce its dynamic nature.
> The complete set of variables need might not be known at compile-time,
> so how could they be declared?
This isn't a valid counterargument, at least for function locals. The
Python compiler does determine all the local variables used in a
function at compile time. Declarations merely force the human
programmer to do something the compiler could do automatically, all
for the sake of catching an occasional typo.
> As an example, imagine that I write a RPC
> client that must be able to receive proxies to object instances. How
> would I know what variables that object has at compile-time?
Those are attributes, not variables. I don't believe the OP was
suggesting that we be able to declare attributes; and if he were, we
could tell him that Python optionally allows that with __slots__.
> I also
> might want to do something wacky like write a module that exposes
> environment variables as globals (like PHP does). How would I know what
> variables I need a compile-time?
Well, globals are attributes of a module, but they kind of behave like
variables when in the module's scope. I don't know if the OP was
suggesting declarations in the global scope, or just the local scope,
but global declarations would certainly interfere with Python's
dynamic nature.
--
CARL BANKS
More information about the Python-list
mailing list