Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

OO in Perl 6

by Scott7477 (Chaplain)
on Oct 16, 2006 at 22:48 UTC ( #578618=perlmeditation: print w/replies, xml ) Need Help??

In his latest Apocalypse, Larry Wall indicates that Perl 6 "uses . instead of -> to dereference an object" due to the idea that "The use of arrow where most of the rest of the world uses dot was confusing." I think that this is a Very Good Thing, for a couple of reasons.

One reason is less keystrokes; going from the dash key to the ">" key has always seemed a little bit of a pain:) The second reason is that this change will likely facilitate introducing people to using Perl. This will be one less thing for folks new to Perl to go "Huh?" at when you show them some code.

Replies are listed 'Best First'.
Re: OO in Perl 6
by revdiablo (Prior) on Oct 17, 2006 at 17:22 UTC

    I agree that the dot syntax is a bit easier to type, and I think overall the syntactic change is worth the (very small, for me anyway) pain it takes to re-learn. A more significant change, in my mind, is how most object code will actually be written. It won't take nearly as much code to accomplish the same goals. Consider an example:

    class Point { has $.x; has $.y; method str { return $.x ~ "x" ~ $.y; } } my $point = Point.new(x => 2, y => 3); say $point.str;

    Compared to the equivalent Perl 5:

    { package Point; sub new { my $name = shift; my %attr = @_; return bless { %attr }, $name; } sub x { my $self = shift; return $self->{x}; } sub y { my $self = shift; return $self->{y}; } sub str { my $self = shift; return $self->x . "x" . $self->y; } } my $point = Point->new(x => 2, y => 3); print $point->str, "\n";

    I think you'll agree that the Perl 6 version makes it a lot easier to get on to the heart of the matter. I really like it.

    (Of course, we can get most of the same conciseness in Perl 5 with Moose, which I am very excited about. But that came as a result of the Perl 6 OO design, so credit where credit is due.)

Re: OO in Perl 6
by Limbic~Region (Chancellor) on Oct 17, 2006 at 12:37 UTC
    Scott7477,
    Please note that the Apocalypses are considered historical documents. The Synopses now serve as the living design document where S = "spec" as well as "synopsis".

    Cheers - L~R

      Thanks for the tip, Limbic~Region. Just shows I need to do a little more RTFM (reading the flaming manual, as I like think of that acronym):). I appreciate the other comments as well. I agree that changing from the arrow to the dot is a relatively minor change in the realm of things that will be different in Perl 6 vs Perl 5. I came to Perl from the world of Visual Basic, where object methods and properties are invoked/referenced using the dot operator. As monarch's comment implies, which operator you are most comfortable with likely will depend on the thought processes you have ingrained in your brain based on the sum of your coding experience. Fortunately, with Perl, TMTOWTDI...

      P.S. I don't think one should underestimate the "stickiness" of certain conventions, even in the face of apparently superior technical advancements. I'd be willing to bet that a majority of monks type out their comments, code snippets, etc. on QWERTY keyboards where the layout is obviously optimized for use with mechanical typewriters. So why not switch to the dot prompt, which legions of programmers are already comfortable with?
        While it is true that the Perl 6 design is still floating around a bit, the switch from "->" to "." is pretty much engraved in stone.

        If you really want to keep track of what's going on with perl 6, you should probably be at least skimming the perl 6 mailing list weekly summaries.

        You can also peruse the "Perl 6 Design Meeting Minutes" over at use.perl.org, but you should be forewarned that it's not likely to give you the warm fuzzies about the progress of Perl 6. For example:

        • 11 October 2006
          Larry:
          * only redesigning the basic syntax of the language
          * other than that...
        • October 06, 2006
          Larry:
          * getting caught up with work after my Europe trip
          * attempting to use Perl 6 for some of that
          * Pugs is not terribly fast at that, so it's not entirely practical
          * getting some experience with programming Perl 6
          * it's kinda cool
          * but in spots I think "who thought up this?"
      Scott7477,
      Please note that the Apocalypses are considered historical documents. The Synopses now serve as the living design document where S = "spec" as well as "synopsis".

      Indeed. BTW it is my understanding that the switch from -> to . has been planned since such a long time, nay I would say since the very first thoughts about Perl 6. Actually I'm of the school of thought that it won't matter much re perl acceptance from people coming from other languages, though there are tons of good reasons why it may be desirable. Just consider dereferentiotion on the implicit topic a.k.a .method(), or the compound operator .= which fits so nicely e.g. in many object constructions, as we have seen.

Re: OO in Perl 6
by GrandFather (Saint) on Oct 16, 2006 at 22:58 UTC

    Heh, may save my 'fat comma' (=>) / 'dereference' (->) confusion when my fingers are on auto-pilot.


    DWIM is Perl's answer to Gödel
      We all have our personal flaws.. I have mine.. though mixing => with -> has never been one of them.

      I guess, in my mind, references to objects are pointers. That's how I do it in my brain. And dereferencing a pointer in C uses the -> notation. I never really got into C++ which uses the concept of references that "appear" to be actual variables, hence the desire to use dot (.) notation to access the contents of a structure/object.

      Perl 5 does it well enough for me for now.

Re: OO in Perl 6
by Anonymous Monk on Oct 17, 2006 at 07:41 UTC
    The second reason is that this change will likely facilitate introducing people to using Perl.

    I don't buy this. If this was really a reason, they wouldn't have introduced gazillion things that no other language has in that form. Perl6 will be much further from anything a novice Perl programmer has encountered in other languages than Perl5; the dot vs arrow is insignificant. OTOH, it's one more thing that Perl5 programmers will learn if they switch to Perl6. Now, perhaps the Perl6 gang is more interested in drawing non-Perl programmers to Perl6 than it is in drawing Perl5 programmers to Perl6, but I think the biggest pool of Perl6 programmers will have to be drawn from the current Perl5 crowd.

    Besides, the entire world doesn't use ".". Java does, and perhaps Perl wants to look more like its bigger and more important brother, but there are still some languages out there that use ->. Pike for instance.

      It's not just Java that uses the dot. Ruby, JavaScript, C++, Eiffel, Python, Object Pascal, Oberon, and C are a few languages that use the dot for dereferencing one thing or another.

      PHP also uses -> for methods and such, but I don't remember the last time I wanted Perl to have syntax decsions based on PHP.

      As for frequency analysis (Huffman Coding), as often as people dereference stuff in modern Perl, it's smart to use an unshifted single key for it. I don't enjoy typing -> all the time, and if it becomes less common I'll appreciate that. Sure, concatenation goes from one unshifted character to one shifted character, but how many times do you concatenate a string vs. passing it around?


      Christopher E. Stith
      Perl6 will be much further from anything a novice Perl programmer has encountered in other languages than Perl5

      True. Yet the majority of those features are optional; what little muckin' about I've done with Perl6 has started from my Perl5 experience, and you can craft what's basically pared-down Perl5 code in Perl6. I think you overstate the effects of many (not all) of the new additions, in terms of programmer impact.

      Besides, the entire world doesn't use ".". Java does

      The simple point is that the majority of OO code written uses the period.

      ----Asim, known to some as Woodrow.

        Especially the quintessential example of object orientation, Smalltalk... er....

Re: OO in Perl 6
by radiantmatrix (Parson) on Oct 26, 2006 at 16:28 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://578618]
Approved by GrandFather
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2021-06-20 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (95 votes). Check out past polls.

    Notices?