[BangPypers] Object Oriented Programming in python
Sirtaj Singh Kang
sirtaj at sirtaj.net
Tue Oct 22 10:34:48 CEST 2013
On 10/22/2013 1:10 PM, Saager Mhatre wrote:
> I guess we're going to have to agree to disagree on that last point. I
> don't find the MOP implementation in Ruby or Groovy less per for many or
> leading to obscure code. On the contrary, I find Python's 'rough-and-ready
> tools' make for more confusing metaprogramming code. YMMV
Right, what I meant was "clarity on behalf of code that most people
write", not necessarily metaprogramming code. As in optimizing for the
> Ah yes, old-style classes! But I'd be hard pressed to call that MOP as
> there are no real metaobjects at play.
Not really true. Using the lingo of the OMG/MDA world: After the
replacement, "MyCircularClass" is an instance of itself and therefore
exists on both M3 (metametamodel) and M2 (metamodel) levels. A new
instance of MyCircularClass (without class change hijinks) exists at M1
(model) level, like a "normal" class instance. What we've gained is a
relatively pure (meta-)class hierarchy to work with, along with the
ability to customize behaviour at all levels using standard python class
and metaclass facilities (__metaclass__, get/setattr, abc). It is more
than enough to build a quite functional purely runtime MOP system.
> Also, you could create/simulate MOP using the tools Python provides you,
> but I'd much rather the platform give me a consistent implementation than
> have to deal with N people each implementing their own special variant of
> what they think MOP should be.
Agreed. All I'm saying is that that stuff usually comes at a cost to
"normal" code. In Common Lisp/CLOS for example, it means that you have
to have the most sparse concrete syntax possible so that any change to
the object model continues to be natural in use.
Not that python couldn't be _better_ at it, but I wouldn't know how to
do it personally.
 This is a reasonable introduction to the OMG-focused philosophy and
terminology of MOP (PDF link):
More information about the BangPypers