I'm thinking about the my Roles talk at YAPC::EU::2009, (you know the conference, right? The one I made that strange little promo for?). It's a bit of a tutorial, but not much. It's more about the "why" instead of the "how" because even though I get plenty of comments/emails about roles, they're almost always in the "why" category. That's because roles are so easy to use once you start that you really need motivation for starting rather than a guide on how to start (though I'll give some of that, too).
One thing I am doing is a bit of comparing/contrasting with multiple languages and how they all struggle to figure out how to manage inheritance. Everyone seems to have a different idea, but I'm stumped on Javascript and other prototyped OO languages.
Prototyped OO languages don't have classes. Thus, you really can't inherit. However, you use an existing object as a "prototype", clone it, and then add state/behaviors as needed. So one might think there's a loose analogy to inheritance there. What I'm wondering is whether or not this enforces a tree-like hierarchy on object systems? Is there any analogue to multiple inheritance? If not, how is this worked around. Every language I've ever used which forbids MI has a workaround (interfaces, mixins or the weird stuff that BETA does). Any other comments about prototype OO languages welcome (particularly if you have experience with examples other than JavaScript).
Take a look through some of the JSAN stuff. There was a bunch of work that got done on implementing what I believe we were calling pseudo-classes.
http://openjsan.org/doc/r/rk/rkinyon/Class/0.05/lib/Class.html
http://openjsan.org/doc/l/ly/lyokato/Class/Setup/0.04/lib/Class/Setup.html
http://openjsan.org/doc/i/in/ingy/Subclass/0.10/lib/Subclass.html
If memory serves, Self had a system to make any slot a parent-slot - by convention "parent*" was the object cloned from, but any slot could be a parent-slot by adding a * to the name. How dispatch was eventually (mis-)handled, I have no recollection...
NewtonScript was based on Self, but extended the convention to always have two parent-slots for gui-elements (business-object + gui-object), but not any more, as I recall.
And speaking of prototype-based language, why would anyone add first-order functions to a language and not make them closures. Yes, javascript, I'm looking at you.
ObUsePerlSucks: adding my own paragraphs? really?
Re:Self and NewtonScript
btilly on 2009-05-23T20:35:26
Huh? JavaScript has closures. They work perfectly well. I've been using them for years.
But there is a major gotcha. Variables declared with var are always scoped to the nearest function call. So if you create closures in a loop, they will all point to the same variable. However once you know that's the issue, that's easily fixed - just call a function from within the loop whose job is to scope the variable correctly.
Re:Self and NewtonScript
lbr on 2009-05-23T21:30:17
Ah, that makes "sense" (and it was that gotcha that had gotten me). Sigh. JINP.
as "Every Class is a Singleton and is Instantiated", which glosses over a bunch of stuff but does roughly fit the way things like Joose are dealing with JS's Prototype OO.
Also Steve Yegge's Universal Design Pattern (aka Propertise Pattern) covers the topic quite thoroughly.
Re:A paper and a post
Ovid on 2009-05-28T19:24:55
Nope, not old news at all. Thanks for the tip!