Stories
Slash Boxes
Comments
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

use Perl Log In

Log In

[ Create a new account ]

Journal of jjore (6662)

Sunday July 08, 2007
11:49 PM

CTM on OO

[ #33748 ]

I started reading Concepts, Techniques, and Models of Computer Programming because it spends a bunch of time discussing concurrency and constraint programming. I was wowwed this weekend when I got to the OO section. I didn't expect anything particularly interesting from this part. Not so.

It solved the allomorphism problem as a "oh, by the way." I just was totally blindsided by it. You can get confused method resolution when your method head is just a string or other atom. This is what happens in perl and just about every OO language I'm familiar with. In the book's pet language, your method head is often a string but isn't required to be. If the head is a "name," an unforgeable identity then it can only be invoked by call sites that have been given the method head.

I suppose this is just a side effect of having first class classes and methods. If you haven't given your method object to a call site, it can't be invoked. This is obvious, right? Still... it's neat and unperly.

Parrot's pdd 15 says methods are invoked by name. Classes, methods, and objects are PMCs though. I can get first class methods in Parrot, right?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I can get first class methods in Parrot, right?

    Yes, but be sure that when you invoke them, you have a valid invocant in the appropriate place. (I thought it was P5, but it looks as if that place has moved.)

  • You can get confused method resolution when your method head is just a string or other atom. This is what happens in perl and just about every OO language I'm familiar with.

    I'm just guessing as to your meaning, but are you referring to the following problem?

      if $obj.can('fribble') {
        my BadPoet $jibbet = $obj.fribble('repeatedly');
      }

    Just because $obj.can('fribble') doesn't mean that fribble() accepts a string or returns a BadPoet instance. I asked about this on the P6 langu

    • if $obj.&fribble:(Str --> BadPoet) { ... }

      Is that, *gulp*, really Perl6?

      I'm just.... Is the point to shock people into not using it? I really need to learn Python or something.

      • No, that was just one suggestion. The problem is that many popular OO programming languages don't really make introspection terribly easy when it comes to determining method dispatch.

        If you can suggest a cleaner, unambiguous syntax which solves the same problem, I'm sure that Perl 6 folk would welcome it. It's also worth pointing out that this isn't something you'd be using a huge amount. Generally it would be shielded from users of your code.

        • this isn’t something you’d be using a huge amount. Generally it would be shielded from users of your code.

          Famous last words…

      • Is the point to shock people into not using it?

        I could loan my four year old nephew Gravity's Rainbow, but I think I'll wait until he's a better reader. The fact that as a thirty-something I had to read The Crying of Lot 49 first doesn't put me off from English altogether.

        • Condescending as always. If your point is that it's confusing to read something when you don't know the language - I know Perl. If Perl6 is so different that I can no longer comprehend it, then it could be called something else like Emerald or Jade or simply Rock.
          • If Perl6 is so different that I can no longer comprehend it, then it could be called something else like Emerald or Jade or simply Rock.

            None of the goals of Perl 6 were "Perl 5 programmers should be able to understand perfectly all code written in Perl 6 without learning anything new."

            Heck, I know Perl 5 pretty well by now and there's plenty of code I don't understand immediately.

          • If Perl6 is so different that I can no longer comprehend it

            How do you change Perl 5 only so much that it requires no learning to comprehend the new features?

    • To my eyes "

      fribble:(Str --> BadPoet)

      " ought to be a pattern. It isn't entirely clear what all the components you'd like to express things about, perhaps just everything that fits into a method head. In Perl 5, this is just its name. In Perl 6, you've also got the type signature for what the method accepts and returns.

      Is there more data available to match against? Perhaps methods can also be "branded" by having something like "tags" attached to it. Imagine a tag swarm for your methods, *grin*!