Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I like to think of allomorphism as describing objects or classes that have the same semantics for a set of behaviors but may be unrelated structurally.

    • Is that any different from the idea of "interface" (as in Java), or is it just a different name for the same thing?
      • Interfaces in Java are horribly broken, but if you ignore the abominable implementation entirely and reconstruct the problem the Java designers almost tried to solve, you can get close to the idea.

        • Could you explain how Java interfaces are broken and how Roles save the day?
          • Java interfaces and types have separate namespaces. Thus if you have a closed library from which you cannot inherit or which you cannot modify, you cannot mark a new type as allomorphic (polymorphically equivalent). It's not really generic programming if you have to modify existing code to make it more generic.

            Java interfaces also don't provide any default implementation. Whereas roles don't dictate any particular mechanism by which the types achieve their allomorphism, Java interfaces are effectively multiple inheritance from abstract base classes (except for the namespace problem). This makes code reuse much more difficult and promotes otherwise unnecessarily deep inheritance hierarchies. It also encourages the arbitrary distinction between extension and implementation.

            Basically the Java designers saw a real problem -- the real world doesn't fit neatly into a singly-rooted inheritance hierarchy -- but didn't go far enough to allow genericity based on semantic behavior without having to copy and paste code or, worse, modify existing code.

            Roles (and I show my bias here) fix all of those problems and make even cooler things possible -- parametrized roles, for example, allow even further specialization and customization. Think of them as class factories that can generate code that conforms to the role based on parameters you provide.

            I certainly look forward to writing less code.