4 ms·
Don't languages with native MOPs, such as Python and Ruby, create better internal DSLs than Perl?
by danellis 13y ago
Don't languages with native MOPs, such as Python and Ruby, create better internal DSLs than Perl?
- kbenson 13y agoThe best I've come up with so far searching for information on MOPs (of the explicit, controllable sort) in those languages is sort-of/almost for Ruby and no for Python. Is there some other name they go by in those languages that I should be aware of?
- danellis 13y agoIn Python the actual features that implement that would be metaclasses and descriptors.
- einhverfr 13y ago> Don't languages with native MOPs, such as Python and Ruby, create better internal DSLs than Perl? Why would you say that? It seems to me that a DSL's function is at least reasonably decoupled from the method it uses behind the scenes, and that there is no real difference between a native MOP (like that in CLOS -- I don't really see an equivalent in Python or Ruby) and a non-native one like Class::MOP in Perl in this regard.
- danellis 13y ago> Why would you say that? It helps you strip out code that isn't related to the DSL. For example, the mechanisms of class definitions in things like MongoEngine or Django's ORM. You end up with something that looks a lot more declarative.
- draegtun 13y agoNope. * Some of the best languages for producing an internal DSL (dialects) don't have a "native MOP". For eg. Lisp, Rebol or Forth. * Python & Ruby don't have native MOP's anyway :) NB. I wonder what you mean by "native MOP" is baked-in OO? Python & Ruby OO systems do come with MOP like abilities. However for full blown (metacircular) MOP (http://en.wikipedia.org/wiki/Metaobject#Metaobject_protocol http://en.wikipedia.org/wiki/Metaobject#Metaobject_protocol) you need to look at things like CLOS & Perl's Moose/Class::MOP.
- danellis 13y agoBy "native MOP" I really mean things like Python's metaclasses and descriptors (and whatever Ruby's equivalents are called), as opposed to an add-on library to simulate them like Moose.
- draegtun 13y agoA bit of apple & oranges going on here because you don't need Moose (or more precisely Class::MOP) to simulate Python metaclasses and descriptors. Because you could, if you so wished, build a Python metaclasse/descriptor based OO system in Perl's native OO. To clarify things: * Python comes with a pre-defined OO system with metaclasses/descriptors for dynamically building new Python classes/objects. * Perl comes with OO lego blocks from which you build you own OO system. * Class::MOP is a metacircular MOP mainly written in Perl using these lego blocks (it's turtles all the way down). * A MOP (like Class::MOP) provide an API for building & managing extendable OO systems. * Moose is an advanced OO system built on Class::MOP. * Moose provides features like Roles, Method Modifiers, lazy attributes and many more. There have been two attempts, that I know of, to bring (a subset of) Moose to Python: https://pypi.python.org/pypi/bullwinkle/0.3.6 https://pypi.python.org/pypi/elk/0.2 There have been many clones of Moose to other languages as well, including Ruby (multiple clones/ports), Javascript & Lua. For something comparable to Moose/Class::MOP then have a look at CLOS (Lisp).