What's up with rebinding assignment?
exarkun at intarweb.us
Fri Mar 21 19:14:03 CET 2003
On Fri, Mar 21, 2003 at 02:24:07PM +0100, Ulrich Petri wrote:
> "Beni Cherniavsky" <cben at techunix.technion.ac.il> schrieb im Newsbeitrag
> news:mailman.1048248875.10571.python-list at python.org...
> > Once upon a time, Just threw in a great (IMHO ;-) idea on pytohn-dev:
> > http://mail.python.org/pipermail/python-dev/2003-February/032764.html
> > The idea was to add am ``:=`` rebinding operator, one that changes a
> > visible binding without making it local to the current scope::
> > [ snipped horrible language abuse ]
> > My question is: is there a chance this will make it into Python?
> > Nobody seems to have noticed it... Will a PEP help?
> The following is strictly IMHO:
> I dont think such an ugly hack will ever make it into python.
> If you need to change a varibale from a higher scope, you most likely have a
> serious design flaw in your program. At the moment i can think of no
> situation where this would be needed. And if there really is such a case you
> can allways define the variable global.
Why is rebinding a variable from a nested scope a design flaw, if reading
it is not?
In my unit tests, I tend to have a lot of things like this:
self.authenticated = 0
self.authenticated = 1
d = self.onConnection.addCallback(auth)
Why should assignment to an attribute of a name in an outer scope be any
different from assignment to an actual outer name? Or does this code
have a serious design flaw? ;)
Making "authenticated" global would be an ugly hack, I have some twenty of
these tests (for -just- this protocol). It's been a -long- time since I was
a bad enough programmer to have twenty globals in my program ;)
And as I see it, having it as an attribute of "self" is an ugly hack as
well. It -is- local to testAuthenticate. Nothing else needs it, -ever-.
Examinations are formidable even to the best prepared, for
even the greatest fool may ask more the the wisest man can answer.
-- C.C. Colton
up 1 day, 13:58, 2 users, load average: 0.18, 0.34, 0.36
More information about the Python-list