Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: What's wrong with Perl 6?

by Cap'n Steve (Friar)
on May 13, 2007 at 05:09 UTC ( [id://615143]=note: print w/replies, xml ) Need Help??


in reply to Re^3: What's wrong with Perl 6?
in thread What's wrong with Perl 6?

It's funny that you compare it to the ugly new Mustangs. You're right that it looks Perlish, but looking at this example from this article, my first guess would probably be Ruby or maybe Java (I don't actually use either of those languages) since the only real clue to its Perlness are the variable symbols, which apparently are used opposite to the way we're used to.
class Staff::Record { has Str $.name; has Int $.rank; has Hash $.pref; method CREATE(Str $name, Int $rank, Hash $cereal_pref) { .check_rank($rank); ($.name, $.rank, $.pref) = ($name, $rank, $cereal_pref); } method name() returns Str { return $.name; } method rank() returns Str { return $.rank; } method rank(Int $new_rank) { .check_rank($new_rank); $.rank = $new_rank; } method check_rank(Staff::Record $obj: Int $rank) is private { die "Invalid rank for $obj.class() object: $rank" unless 0 < $rank < 10; } # Other methods here }

I haven't been programming Perl for that long, but was the change from 4 to 5 anywhere near this dramatic? I know PHP 4 to PHP 5 wasn't a huge deal, and I don't think VB 5 to VB 6 was either.

Replies are listed 'Best First'.
Re^5: What's wrong with Perl 6?
by blazar (Canon) on May 14, 2007 at 09:04 UTC
    It's funny that you compare it to the ugly new Mustangs. You're right that it looks Perlish, but looking at this example from this article, my first guess would probably be Ruby or maybe Java

    That is an example that exhibits explicit features related to Perl 6's OO system. The code is not all that different from Perl 5 (roughly) equivalent one except for some syntactical bits, and the fact that in the latter you should build yourself some stuff that in this case is instead part of the language.

    For "normal" usage, whatever that is, I can't see e.g.

    .say for =$fh;

    as being significantly less perlish than

    print while <$fh>; # assuming $\="\n"

    I would rather say: differently so.

    OTOH I'm glad to be able to do e.g.:

    pugs> sub postfix:<!> (Int $n) { [*] 1..$n } undef pugs> say $_! for ^6 1 1 2 6 24 120 undef

    (As you can see this has the advantage of being able to be already run under pugs - it is also quite about the only thing I can do! :-)

    Even in the example code you presented, though, there are many bits that IMNSHO are very perlish, although also very different from current Perl look and feel:

    • Perl's typical way to do things implicitly on the $_ pronoun, in this case by means of "unary" dot;
    • Perl's dwimmery fashion with 0 < $rank < 10 which is more clear and concise than the full expression comprising a logical operator.

    Also see the following portion of a recent clpmisc thread (link @ GG):

      Well, I guess we have different definitions of "Perlish". I was thinking "similar to past versions of Perl" and you seem to be thinking "conforms to the Perl philosophy". With your example of .say for =$fh;, once again the only thing that I would call Perlish about that is the dollar sign, and if you changed the variable name I'd have no clue what it does.
        Well, I guess we have different definitions of "Perlish". I was thinking "similar to past versions of Perl" and you seem to be thinking "conforms to the Perl philosophy".

        ++ because even if I disagree, you raised some important points. Indeed I was replying much along the lines of what TimToady explained earlier in this thread. Not because I took that as a revelation (although I find it to be so instructive and pleasantly written as usual) but because I'm already much thinking/feeling that way.

        With your example of .say for =$fh;, once again the only thing that I would call Perlish about that is the dollar sign, and if you changed the variable name I'd have no clue what it does.

        Well, then the semicolon appears to be statement delimiter too! ;-) But seriously, there's at least another very perlish thingy: the for statement modifier. This is just the same as Perl 5's. The real difference being that although both in 5 and 6 TMTOWTDI it's also true that in both there's often a preferred WTDI for most common situations, and in Perl 5 we often recommend to use a while loop to iterate over a filehandle unless there's a good reason to slurp the whole file in at a time. This has been occasionally source of confusion. But Perl 6 goes one step further making the whole thing more consistent thanks to its lazy evaluation model, so that for is suitable to iterate over any iterator. Said this, if you compare <$fh> and =$fh, you will notice that the former you're familiar with. The second, not. But if you knew neither, they would be equally strange, perhaps but the fact that the = sign is also used for more familiar things, like assignment; OTOH as $Larry says, the unary one also visually conveys the idea of lines from a file and thus does make sense. Last, say() is something that semantically has been missing in Perl for a long time, but then its name strongly suggests what it does. I'm not commenting on the dot and in particular the unary one, which is... well not much pre-6'ish, but is indeed very perlish in the sense above.

Re^5: What's wrong with Perl 6?
by BrowserUk (Patriarch) on May 14, 2007 at 09:41 UTC

    An almost complete aside from the purpose of this thread, but it comes as a direct result of seeing a little real-world(ish) Perl 6 code posted here.

    I can see that pieces of code like this from above are likely to be quite common in Perl 6 class implementations:

    ($.name, $.rank, $.pref) = ($name, $rank, $cereal_pref);

    Ie. The assignment of batches of named formal parameters to instance variables with the same (similar, the $.pref/$cereal_pref disparity not withstanding) names. And vice versa.

    Is there any shorthand available for this kind of 'batch assignment' from method parameters to instance variables?

    I was thinking along the lines of $.= ( $name, $rank, $pref );

    and say $= ( $.name, $.rank, $.pref );

    Is there any mileasge in that?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      IIRC, naming your method parameters as if they were instance variables accomplishes that trick:

      method foo($.name,$.rank,$.pref) { ... } # and then later ... $obj.foo('Scott', 'Vicar', '???'); # sets the instance vars
      Though pulling out the auto-magic into something you can do directly is interesting.

      Check S12 in any case for the definitive answer.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://615143]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-29 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found