[BangPypers] Object Oriented Programming in python

Saager Mhatre saager.mhatre at gmail.com
Mon Oct 21 15:12:33 CEST 2013


On Oct 21, 2013 3:21 PM, "Dhananjay Nene" <dhananjay.nene at gmail.com> wrote:
>
> On Mon, Oct 21, 2013 at 3:02 PM, Saager Mhatre <saager.mhatre at gmail.com>
wrote:
> > On Oct 21, 2013 12:09 PM, "Dhananjay Nene" <dhananjay.nene at gmail.com>
wrote:
> >>
> >> On Mon, Oct 21, 2013 at 11:53 AM, Saager Mhatre <
saager.mhatre at gmail.com>
> > wrote:
> >> > On Oct 21, 2013 11:39 AM, "Dhananjay Nene" <dhananjay.nene at gmail.com>
> > wrote:
> >> >>
> >> >> On Mon, Oct 21, 2013 at 10:55 AM, Saager Mhatre <
> > saager.mhatre at gmail.com>
> >> > wrote:
> >> >>
> >> >> > Which generally lead to poor (or at least poorer) abstractions;
but I
> >> > digress.
> >> >>
> >> >> Leaky ??  :)
> >> >
> >> > For the most part, yes.
> >> >
> >> >> >
> >> >> >> I think OOPs concepts across a number of languages are quite
> > different.
> >> >> >> You will find python having superior constructs eg. metaclasses
etc.
> >> > if you were comparing Python OOP to C++/Java.
> >> >> >
> >> >> > Superior constructs implemented inferiorly. Meteclasses are much^3
> > more
> >> > powerful in Groovy, Ruby and SmallTalk (where some would claim Python
> >> > borrowed them from; but that's just not true.)
> >> >>
> >> >> I wonder if you meant syntactically/stylistically. Would be keen to
> >> > learn, if there are examples where ruby / groovy (I don't know much
> > about
> >> > smalltalk) allow things that python does not.
> >> >
> >> > Semantically! MetaClasses are a much more powerful construct in those
> >> > languages.
> >>
> >> I'm specifically looking for evidence to support that. And I suspect
> >> it might be out there to be found , just that I haven't so far. One of
> >> my early attempts was documented here
> >>
> >
http://blog.dhananjaynene.com/2010/01/dynamically-adding-methods-with-metaprogramming-ruby-and-python/
> >>
> >
> > Don't look for metaprogramming, you'll end up with a lot of ancillary
> > stuff. Look for metaclasses or metaobject protocol.
>
> Is there an example or two which demonstrates ruby can do things via
> metaprogramming / metaclasses / metaobject protocol that python cannot
> ? Something more than syntactic or stylistic differences.
>
> It wouldn't be normally fair for me to ask for that and I should go
> hunt it down myself, but given the earlier assertions made in this
> thread, i believe it is reasonable in this case.

Sorry, on GPRS, so hunting for videos will kill my phone & tablet. Add
'Yehuda Katz' or 'wykatz' in your queries; methinks he's done a bunch of
talks about this. There was also one from the RuPy conference, but I don't
remember if it dealt with metaprogramming per se. But you should be able to
find some videos. That said, it might be hard to find comparisons as the
Ruby folk usually just outright ignore Python, the Groovy folk are too busy
embettering Groovy and the SmallTalk folk are in a cave somewhere that I
know not of!

Also, just to clarify, metaprogramming is distinct from metaclasses and
presence of one in a platform is not essential to the presence of the
other. Metaprogramming is more to do with code that writes, unwrites or
modifies more code; while metaclasses are about some seriously dynamic
dispatch.

Incidentally, that is another place Python's implementation departs from
metaclasses in other languages. Where Python provides metaclasses as a hook
to rewrite class internals/implementation before it becomes available to
other code, other platforms attach metaclasses to classes (or objects, in
some cases) at runtime to control/alter the way messages to/methods of the
class (or object) are dispatched. Python conflates metaprogramming into
metaclasses where it is not a necessity, in that Python metaclasses can do
little more of value than add/remove/modify attributes of the class; in
other words, metaprogram elements of class definition.

Man, I should start a list of misnamed concepts in Python! Hey, there's my
talk for the next PyCon- Python, the misnamed bits! :D

That said, I've been meaning to do a decent talk on metaprogramming and
wanted to do a first round at PythonPune. Maybe if thinrhino bugs me about
it enough, I might just... :)

- d


More information about the BangPypers mailing list