March 2016 Archives

"Wow, Perl 6!" Talk: Slides, Recording, and Answers to Questions

Last night I gave a "Wow, Perl 6!" talk at the Toronto Perl Mongers, whom I thank for letting me speak, even after I got lost for 15 minutes in the building the event was hosted at and was subsequently late.

The talk is an overview of some of the cool features Perl 6 offers. If you didn't get a chance to be at the talk or to watch it via a Google Hangout, you can still get a recording of it.

You can view the slides at http://tpm2016.zoffix.com/ and the recording of the talk is on YouTube:

Synopsis

Couch Potato:

  • Lazy lists and their uses

Molding Your Own:

  • Subsets
  • Custom operators
  • Muti-dispatch

Hyperspace: Multi-core processing at a touch of a button

  • Hyper operators
  • Hyper sequence methods
  • Autothreaded junctions
  • Promises, Supplies, and Channels

How's Your Spellin'?

  • Grammars: Parsing made easy

Whatever, man!:

  • Whatever Code
  • Meta operators
  • Model6 Object Model (very brief "teaser" overview)
  • MOP: Meta Object Protocol
  • Sets, bags, and mixes

Polyglot:

  • NativeCall
  • Inline::Perl5

Not Really Advanced Things:

  • Hacking on the Perl 6 Compiler

Bonus Slides:

  • Backtraces for failures in concurrent code
  • Peculiarities with Rats
  • Proc::Async
  • say is for humans put is for computers
  • More useful objects
  • Built in profiler

Answers to Questions

During the talk a couple of questions were asked and I didn't know the answer at the time. I do now:

Is there a way to have better error messages when a subset doesn't match a value given?

The code in the where can be anything you want, so you can warn or fail inside the check to get a better error message. Once caveat: the argument given to callframe might be different depending on where you're performing the check. Try adjusting it:

subset Foo of Int where {
    $_ > 10_000
        or fail "You need a number more than 10,000 on "
            ~ "line {(callframe 4).line}, but you passed $_";
};

my Foo $x = 1000;

# OUTPUT:
#  You need a number more than 10,000 on line 7, but you passed 1000
#  in block <unit> at test.p6 line 2

Can you check whether or not a value fits the subset?

Yes, just smartmatch against the type/subset:

subset Even where * %% 2;
say 3 ~~ Even;
say 42 ~~ Even

# OUTPUT:
# False
# True

Can you have an infinite Set?

No, it tries to actually create one. Makes sense, since a Set cares about the elements in it. Sure, it's possible to special-case some forms of sequences to figure out whether an element is part of the sequence or not, but it's probably not worth it. In a more general case, you are faced with the Halting Problem. Speaking of which, here is a gotcha with the sequence operator and the upper limit:

my @seq = 0, 2 ... * == 1001;

Here, I'm using the sequence operator to create a sequence of even numbers, and I'm limiting the upper bound by when it'd be equal to 1001. But it won't ever be equal to that. To human brain, it might seem obvious that once you're over 1001, you should stop here, but to a computer it's a Halting Problem and it'll keep trying to find the end point (so it'll never complete here).

Can you kill a running Promise?

Not possible. If you need that kind of thing, you'll have to use processes, or you'll have to build the code inside the Promise so that it exposes some kind of a "should I continue working?" flag.

Links for Learning Materials and Ecosystem

Along with http://perl6intro.com/ that I mentioned during the talk, there's also Learn X in Y Minues Perl 6 page, which I personally found very useful when just starting out with Perl 6.

The Ecosystem is at http://modules.perl6.org/ you should have panda program installed, and you can install modules from the Ecosystem by typing panda install Foo::Bar

Perl 6: The Next Node.js, Done Right

If you've been a programmer for more than a couple of years, then you remember when Node.js first appeared. Some folks were raging about how insanely fast their ecosystem was growing, while others confusedly shrugged, wondering why anyone would want to use a language made for scripting browsers for server side work.

I can easily dismiss Node's large ecosystem of reinvented wheels, but the underlying point of why it got popular is valid: the fewer languages you need for an app, the fewer (or less experienced) programmers you have to hire, the cheaper it is to make your app. The self-proclaimed "HTML programmer" who was copy-pasting JS snippets from blogs and forums, now of all a sudden became a full-stack Web developer. But is using a made-for-browsers language for all-purpose work the right approach?

If you follow news or social media, today you definitely saw an article that invariably had a stock photo of someone playing Jenga. To sum up: lawyers pressured a developer to rename an NPM package. Developer refused. Lawyers came to NPM admins, who obliged to do so. The enraged developer then unpublished all of their NPM packages and the huge swath of the Interweb that depended on those packages chaotically crumbled and sufficient mocking of the whole system ensued.

The whole ordeal made me think of how such a situation might have played out in the Perl community. Would PAUSE admins remove an indexed module due to a request from lawyers, even when the author is responsive? Knowing personalities of a few of them, I doubt so. A communication channel among the involved parties would've been established instead.

And were a critical package actually deleted by someone, we have BackPAN, GitPAN, and dozens of slow-refreshing mirrors. We wouldn't need to take NPM's "an unprecedented step" to restore order to chaos. The system would've worked fine for awhile, and the breakage would be restricted to telling people to specify an actual package URL to the cpanm client. Not to mention, the NPM package that caused most of the breakage was tiny and some question why that little bit of code was even a dependency in the first place.

Going back to ecosystems. Browsing NPM, I can barely find packages with documentation, let alone tests for them; and I'm not the only one questioning quality. The Perl community, on the other hand, is a community of comprehensive tests. The quality of packages without tests is viewed with inherent suspicion and I've participated in many group mockings of packages that had no tests. Not to mention things like CPANTS Kwalitee Game that has "has tests" metric.

So what does my rambling have to do with Perl 6? The answer is the Perl 6 JavaScript Backend. Lead by PaweĊ‚ Murias, the project was recently accepted for a grant and is well on its way to being usable.

You write Perl 6 code for both your backend and your frontend. The Perl 6 meant for the frontend gets compiled to JavaScript, so it can run in any browser that hasn't yet implemented native Perl 6 scripting in its core (c'mon, I can dream!). This is a complete inversion of the Node's paradigm: instead of a limited browser language made all-purpose, an all-purpose language's subset is made available in browsers. Throw into the mix the maturity and test-oriented culture of Perl, and I think you've got Node.js, Done Right.

So is the Jenga of Node starting to tumble down? Are we starting to realize the fad popularity of a language isn't the sole reason why your company should use it? Is there a successor ready to replace Node? Right now, I can only speculate, but in a couple of years, I'm sure Perl 6 will be the shiny new tool of a full-stack Web developer.

About Zoffix Znet

user-pic I blog about Perl.