Sujet : Re: Languages (was: Re: More Funny Stuff From The Joke Python)
De : sebastian (at) *nospam* here.com.invalid (Sebastian Wells)
Groupes : comp.os.linux.advocacyDate : 24. Jun 2024, 10:58:32
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5bcfo$7182$4@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Pan/0.154 (Izium; 517acf4)
On Sun, 9 Jun 2024 01:11:33 -0000 (UTC), Lawrence D'Oliveiro wrote:
On Sat, 8 Jun 2024 21:48:32 -0000 (UTC), vallor wrote:
My go-to language has always been perl ...
I did Perl for some years, but always felt that there were things
potentially going on that I could never quite understand.
When I tried Python for the first time, that feeling went away. It was
always clear to me what the code was doing, and why--no mysterious
magic,
no surprises.
Then you haven't delved deeply enough into Python.
I had to debug a project where code similar to the following was
calling invisible methods:
foo.bar = 'baz'
It turned out that the statement above does not overwrite
the value foo.bar with a string, because bar's value was
a special object that overrode the assignment operator
by virtue of being the value of an attribute on another
object. "foo.bar" without an assignment was also overridden,
for the same reason.
The thing that made foo.bar's actual value special was that its
class defined the magic methods __get__, __set__, and __delete__.
I don't remember how I discovered the existence of this object.
Even Python's getattr() and setattr() functions are overridden.
This "feature" of Python is little known.
The invisibility of these objects is so bullet-proof that the
only way you'd become aware of one is if one of the three
magic methods threw an exception.