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

Re: sort +*, @array

by sundialsvc4 (Abbot)
on Dec 10, 2013 at 16:21 UTC ( #1066458=note: print w/replies, xml ) Need Help??

in reply to sort +*, @array

“Brevity” is not necessarily a virtue.   The comment above, “what does this piece of code actually do...?” is actually very telling, IMHO.

#define SOAPBOX

#undef SOAPBOX

Replies are listed 'Best First'.
Re^2: sort +*, @array
by raiph (Chaplain) on Dec 10, 2013 at 23:03 UTC
    I agree with the sentiment that clarity, in most scenarios, is far more important than brevity. But you surely aren't suggesting that code should be so obvious that even someone who doesn't know a given language or dialect automatically knows exactly what code in that language or dialect means?

    That said, P5ers ought to be most of the way there:

    • The sort is a (builtin) function call.
    • The prefix + coerces to numeric.
    • The * is a Whatever. (A P6 innovation, explained below.)
    • The , is the comma operator. (P6 has cleaned up the P5 warts. The comma operator never returns the last value; even in item context it returns a list, as most people would expect.)
    • @array is an array variable.

    All of this is absolutely obvious to even a beginner P6er.

    Many P5ers won't know what a Whatever is, and won't know the way the sort builtin interprets closure arguments, so I'll explain those:

    • The Whatever is as pervasive and basic in P6 as the $_ ("it") variable is in both Perls. In many scenarios, such as this one, a single Whatever means { $_ }. Add in the prefix plus and you have sort { +$_ }, @array.
    • The sort builtin interprets a single arg closure as its first arg as a "key extractor", which is the clean P6 abstraction of what the map at the start of a P5 ST is comparatively crudely abstracting.

      This is a useful explanation, thanks.

      However, it seems to me one of the issues "P5ers" have with P6 is, that they can never rely on symbols in P6 having the same meaning as in P5. You give the comma operator as one example and I am using it a lot to retrieve the last element of a list.

      So the P5ers might be there most of the way but they would not know for certain...

        it seems to me one of the issues "P5ers" have with P6 is, that they can never rely on symbols in P6 having the same meaning as in P5.

        I don't have a problem with P6 syntax being different to P5; even where those differences are subtle enough to catch me out a few times. The products of evolution -- when enough beneficial mutations have accumulated -- are always new species. They live along side each other without interbreeding for a while, and, if the mutations are truly beneficial, they eventually out compete their progenitors and take over niches wholesale.

        In the 10 years since I first became aware of the possibility of P6; I've learnt enough of at least a dozen new languages to try them out on a few sufficiently complex problems that I could compare and contrast their benefits and drawbacks for myself. For the most part, different syntaxes don't bother me too much if they aren't too obscure, are reasonably well documented, and aren't too verbose.

        My assessment of the bits of P6 I've seen/picked up are that it would be right up my street; and that the learning curve would definitely be worth the effort for the gains.

        My only real problem(*) with P6 itself is that for most of the things I do, it simply isn't fast enough. I quite frequently will wait many hours or days for a P5 program to complete -- when I know full well that written in C, or D, or C++ or Java, it would perhaps take 1/2 the time or less -- because I know that it would probably take me longer, than the P5 code takes to run, to write the program in those other languages. That's what keeps me using P5 for the majority of my code.

        But to have to wait a month for P6 to do what p5 does in 2 or 3 days is too much; the gains from the new syntax simply aren't enough to justify it.

        (*)The other problem is the hyperbole and broken promises...

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        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.
        Yes, compared to those who don't know any Perl, "P5ers" have, on the one hand, a head start (the many identical aspects of P5 and P6) and, on the other, the frustration/confusion that arises from changes including many seemingly random subtle ones.

        Some things to consider:

        • I've witnessed (and occasionally participated in) continual discussion over the years of established aspects of Perl, from the spelling of keywords and various idiosyncrasies to muscle memory and common P5 mental models, and of minimizing and mitigating the impact of changes between P5 and P6.

        • This isn't just theory. Many P6ers are also P5ers and clearly don't like being confused or frustrated when switching between the languages. These P6ers are dogfooding the switching experience and improving it as they go.

        • The compiler is helpful. There are many warning and error messages that reflect knowledge of P5isms, their corresponding P6isms, and how to help folk switch.

        • Several folk have written P5-to-P6 doc, eg Moritz's P5 to P6 articles. Unfortunately a lot of it is out of date which of course increases the sense of uncertainty. :(

        • There are P5 and P6 evalbots on #perl6 and #perl6ers are eager to help anyone wanting to learn P6, including skeptical P5ers. (This is the primary antidote for the previous point.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1066458]
and a moth chases the moon...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2017-06-23 04:26 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (534 votes). Check out past polls.