[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tmda-workers
Subject:    Re: CVS: tmda/TMDA Pending.py,NONE,1.1
From:       Tim Legant <tim-dated-1038878284.0fd8c4 () catseye ! net>
Date:       2002-11-26 1:18:02
[Download RAW message or body]

David Guerizec <david@guerizec.net> writes:

> This is the magic of references, once you get used to it, you can't do
> without (well sometimes it bites you too!).

I'm not sure it's a reference issue so much as a Python language
design issue -- if you assign to a variable, Python will create it out
of nothing if the name is not known.  Reference-based languages don't
have to do that; they can require a declaration before use[1].  On the
other hand, if a variable is accessed (not assigned to), Python will
find that name in an entirely different namespace if it doesn't exist
in the current nameapce (local vs. class, for example).

It's mildly weird, but it does protect against accidently writing the
wrong variable since you have to be explicit about the ones you want to
write (either "global <varname>" or "self.<varname>" or
"<classname>.<varname>") unless it's a local.

> > I have been writing Python for almost 5 years and was unaware of
> > that distinction.  Ya learn something new every day!
> 
> Maybe I was aware of that because as a true beginner I just read
> 'Introduction to Python' during my last holidays ;)

Awesome!  Welcome to the Python world :)

I read that article a number of years ago and must have just gotten
the other idea into my head at some point.  I rarely find a need to
write code that updates class variables, so I haven't been bitten!

BTW, tmda-pending looks very nice now :)


Tim

[1] I worked for The Whitewater Group from '90-'92.  One of their
products that I worked on/with was an object-oriented reference-based
language called Actor that ran on Windows.  Declarations were required
for local variables; just the name, since variables, like in Python,
were not typed.
_________________________________________________
tmda-workers mailing list (tmda-workers@tmda.net)
http://tmda.net/lists/listinfo/tmda-workers
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic