[Python-3000] Special methods and interface-based type system
krstic at solarsail.hcs.harvard.edu
Thu Nov 23 01:19:03 CET 2006
Bill Janssen wrote:
> 1) Mainly, all methods are special to someone.
But some, such as those that have special meaning to the language
itself, are more special than others.
__methods__ are not just plain old methods with funny names. You write
regular methods to express functionality you wish your class to have,
but you write __methods__ to provide low-level glue tying your class in
with the interpreter. This lets the interpreter maintain a kind of
pleasant fiction in which user code can depend on system methods, like
len() or attribute access, returning sensible results and performing
sensible actions even for objects the user code knows nothing about.
This difference is substantial enough that a different terminology has
been quietly tossed around: the name `defop` implicitly proposes that
__methods__ are really "operations". I'm not sure if I like the term
yet, but in the meantime, thinking about these methods as system glue,
staples, paperclips, or a different fastener term of your choice, might
illuminate the difference further. :)
Ivan Krstić <krstic at solarsail.hcs.harvard.edu> | GPG: 0x147C722D
More information about the Python-3000