Live data from Hacker News

Why I’m Learning Perl 6

evanmiller.org

211–220 of 380 posts

Re: Why I’m Learning Perl 6

#211
post #191

Earlier quoted context omitted.

I highly recommend that you try out a language with good support for option/maybe types: Haskell and Rust are good options here. Very often, your error handling through a chain of operations will be to use a slightly different operator (say '?.' Instead of '.') and any errors will be automatically propagated to the end of that section of code where you can handle them all in one place. Alternatively, give Erlang or E…

> I highly recommend that you try out a language with good support for option/maybe types Right. Like Perl 6. > Very often, your error handling through a chain of operations will be to use a slightly different operator (say '?.' Instead of '.') and any errors will be automatically propagated to the end of that section of code where you can handle them all in one place. P6 does this stuff particularly well. It makes o…

How is "opt-out option types" different from, say, Java, where everything is nullable and all the problems that come with that?

Honest question, as I haven't had a chance to look into P6 as much as I would like. It looks pretty cool in a lot of ways, but I'm worried that all of the options available would create a confusing mess.

> Note that the author of the OP is well known in the Erlang community.

Yeah, my comment was directed at the parent who asked:

> I don't understand how some other language would not need to handle all the errors ?

And was intending to give a brief description of how other languages (possibly including P6, though I don't have the experience to say) handle errors differently from the languages they listed (go/java/php/python/js).

Re: Why I’m Learning Perl 6

#212
post #73
post #65

I hate perl6. I hate it because I tried to get involved in the project early on, and it led me down the Haskell rathole. I don't know what Haskell looks like today, but a decade or more ago it was the hardest language to pick up that I had ever experienced. It was as if I had a solid background in latin languages and I was trying to pick up Chinese based on a handful of tutorials written by a tourist on the back of a…

I looked quickly through the slides and saw that perl has now grammar build in the language... Truly an interesting feature

There is an old (infoq? I think) presentation with Damian Conway where he calls it a new paradigm "grammar based programming" where you write a grammar parser object easily using the built-in functionality and then add a little code to get with it and BAM you're finished. I think this elegantly solves quite a few programming tasks of mine.

Re: Why I’m Learning Perl 6

#213
post #73

Earlier quoted context omitted.

I looked quickly through the slides and saw that perl has now grammar build in the language... Truly an interesting feature

Is the language itself a good place for parsing/grammar handling? I could not even find in the standard documentation which kind of parsers it supports, is it LR(k)? LL(k)? Any CFG? What parsing method does it use: recursive descent, shift-reduce, something more general like CYK/Earley algorithms? How does it handle ambiguities? It turns out that `grammar` keyword generates recursive descent parsers and anything even…

> It turns out that `grammar` keyword generates recursive descent parsers

Yes, P6 grammars generate recursive ascent/descent parsers.

(It allows arbitrary mixes of ordinary P6 closures, using the 'Main' DSL's syntax, with parsing P6 closures, using the 'Regex' DSL's parsing syntax. Purely declarative parts of the latter are true regular expressions and are mapped to automata by the compiler.)

> and anything even a bit fancier still requires a dedicated parsing library.

Huh?

Please explain what it is about the Perl 6 grammar (the grammar for Perl 6 that is itself a Perl 6 grammar) that isn't fancy.

In my recent SO post [1] I wrote "In most cases, the practical answer when you want to parse anything beyond the most trivial of file formats -- especially a well known format that's several decades old -- is to find and use an existing parser.". Is this what led to your "bit fancier" conclusion about P6 parsing?

> Is the language itself a good place for parsing/grammar handling?

Yes.

Not only does this allow devs to more easily write and use parsing code, just as P5 made it easier to write and use regexes, but it also makes it easier to mutate Perl 6 and write DSLs.

[1] https://stackoverflow.com/questions/45172113/extracting-from...

Re: Why I’m Learning Perl 6

#214

Crystal ( http://crystal-lang.org ) has fibers and channels. Current implementation isn't multi-threaded but it's being worked on. So you'll get that concurrency + nice syntax + types + a wonderful stdlib. EDIT: as seen in other responses, options abound: Python 3, Elixir, D, Dart and more all have built-in concurrency primitives, not to mention that discarding nodejs because of "callback hell" is at this point laugh…

I am really,really excited about Crystal. I wish it success but I am afraid if the rails shops and big companies do not start using it it will be too little too late.

That would be unfortunate. I really like Crystal as a fast, typed alternative to Ruby, but I also prefer Ruby as a language to Go or even Elixir, which not everyone does.

Re: Why I’m Learning Perl 6

#215
post #67

Earlier quoted context omitted.

I wish Linux distros shipped with more recent language versions, e.g. Python 3.6 and Perl 6 in addition to just 3.4/5 and 5. I understand that it's not their job to try and push people to update their language skills, but it'd be nice to have access to them right off the bat if they feel like it.

Red Hat 7.3 ships perl 5.16.3 - it's from 2013. 6.9 ships perl 5.10.1 from 2009.

    $ cat /etc/redhat-release
    CentOS Linux release 7.3.1611 (Core)

    $ yum info rakudo
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirror.team-cymru.org
     * epel: mirror.oss.ou.edu
     * extras: mirror.cloud-bricks.net
     * updates: mirror.atlantic.net
    Available Packages
    Name        : rakudo
    Arch        : x86_64
    Version     : 0.2017.04.2
    Release     : 1.el7
    Size        : 3.4 M
    Repo        : epel/x86_64
    Summary     : Perl 6 compiler implementation that runs on MoarVM
    URL         : http://rakudo.org/
    License     : Artistic 2.0
    Description : Rakudo Perl 6, or just Rakudo, is an implementation of the
                : Perl 6 language specification. More information about Perl 6 is available
                : from . This package provides a Perl 6 compiler built for
                : MoarVM virtual machine.

Re: Why I’m Learning Perl 6

#216

For some reason, when I started my software engineering career I got it into my head that I needed to learn as much as I could about programming languages. I learned ruby, perl5, python, lisp, forth, ml, ocaml, scheme, haskell, r, c#, java, lua, c++, factor, idris, asm, erlang, prolog, rust, d. But that wasn't quite enough because haskell and idris kept on talking about complicated type theory stuff. So I also learne…

Think of it as incorporating many of the features in all of the languages you mentioned above, but in one language that is designed to grow. The language can easily be enhanced both officially and by the end user. So not too many new concepts for you, just a different syntax.

Re: Why I’m Learning Perl 6

#217
post #18

Can anyone recommend a good book on Perl 6? Are there any (even bad ones)? Right now I feel the major reason that keeps me from investing time in Perl 6 - besides adoption by distros - is the lack of a good book, like the Lama and the Camel book for Perl 5. It's kind of frustrating after having waited so long.

> adoption by distros This has improved, and I think most distros now ship Rakudo (Perl6 on MoarVM). At least: Debian, Ubuntu, Fedora, and Arch do.

CentOS 7 has a package for it if you enable the EPEL repo.

Re: Why I’m Learning Perl 6

#218
post #18

Can anyone recommend a good book on Perl 6? Are there any (even bad ones)? Right now I feel the major reason that keeps me from investing time in Perl 6 - besides adoption by distros - is the lack of a good book, like the Lama and the Camel book for Perl 5. It's kind of frustrating after having waited so long.

Think Perl6 is already out and free to download...very well written!

Re: Why I’m Learning Perl 6

#219

> Concurrency is hard and if you want M:N thread multiplexing (i.e. WEB SCALE CODE, where application threads aren’t pinned to pthreads) your options today are precisely Erlang, Go, .NET, and Perl 6. Putting aside the "web scale" jokes ( http://www.mongodb-is-web-scale.com/ ), this statement is still absurd. Every major language, or at least the ones that matter for backend development, has support for thread multipl…

> Every major language, or at least the ones that matter for backend development, has support for thread multiplexing / coroutines / fibers, whatever. M:N threading is not, from a developer perspective, the same thing as coroutines/fibers. Coroutines are lower-level; it's possible to build something like M:N threading on top of coroutines, but it means doing a lot of work that's already done for you in a language tha…

> Coroutines are lower-level [than M:N threading]

Not sure I understand what you're trying to say here, this sounds exactly backwards to my reading. A green threading library can be written in assembly language with no reference to anything but the hardware ISA specification and the ABI that defines the relevant calling convention. It's as "low level" as a software construct can be. The only lower level implementation I can think of are hardware-assisted context switching features like you see on some embedded architectures.

Coroutines, on the other hand, are artifacts of the language runtime and depend in sensitive ways on that whole stack. Much higher level.

Re: Why I’m Learning Perl 6

#220
post #202

Earlier quoted context omitted.

What do you mean by the "side-effect-laden" part? Did you find yourself writing lots of side effecting code because of Haskell (which seems weird)? Or Haskell just wasn't a good fit for a project that was full of side-effecting code? If it's the latter, I can definitely tell you that part of the zen of Haskell is firming up the boundaries between side-effecting code and pure code -- for example, IMHO the better you g…

Writing a purely functional function like, say, factorial, or the Ackermann function, was no problem at all. Writing a "purely" side effect-based one, say, read a string from stdin, parse an age, and say, "What, you are %d years old?!?! Wow, you're old!" completely eluded me. Maybe it was just that all the tutorials I encountered sucked. Maybe I am just too dumb for Haskell. Given that I currently really love Go, I k…

So yeah, I definitely get that. I'm no Haskell master, but I found that my code progressed this way (assuming I was trying to do what you mentioned":

  main :: IO ()
  main = do
  putStrLn "Please input your age:"
  age = 40) (putStrLn "..." ++ (show age))

But as you get more comfortable, you get something like:

  type Age = Int

  -- Imagine there are constants here for youngAgeMessage, middleAgeMessage, and oldAgeMessage, 
  -- for simplicity they're just strings, though you could add even more descriptive aliases 
  -- like "OldMessage" with a quick union type like AgeMesssage = YoungAgeMessage | MiddleAgeMessage | OldAgeMessage, etc etc

  makeAgeMessage :: Age -> String
    makeAgeMessage age
    | age = 40 = oldAgeMessage ++ show age

  main :: IO ()
  main = putStrLn "Please enter your age:"
         >>  getLine
         >>= putStrLn . makeAgeMessage . read

This isn't even the final form of this code either, there are some more things you could do to make this code more axiomatic haskell. This code is approximate (like you probably can't copy and paste it, probably won't compile) but should at least show what I mean.

It's similar to early clojure and the use (and eventual love, usually, of the threading macro "->") and the unix philosophy -- once you start writing those clean functions that pass whatever they need right along, it starts getting easier (and more desirable) to pluck out the parts that don't have to be side-effecting.

Also, the type system expresiveness is just amazing -- it's what Java should have been but never got the chance to be:

  data Thing = OneThing | AnotherThing | ThirdThing
Guess what a `Thing` can be? literally just those things, not even a null or anything. A lot of people say they really love/need/only use "strongly typed" languages (which means a ton of things to a ton of people), but the biggest slap in the face to me is how a language like Java (that people will reach for when they want to compare some usually weaker language to a "strongly typed" one), is a literal minefield of Null Pointer Exceptions (NPEs). "Anything can be anything or sometimes nil" is a hard pill to swallow once you've used Haskell. Also, trying to use Option everywhere feels wrong if you do it in Java, because it starts to bleed everywhere, but actually... it's absolutely right (IMO) -- imagine how much better java code could be if the default was to Option.map over things, and the second you decided to try and pull a value out, you knew you were opening yourself up to something bad, instead of just passing things around and hoping they're there or writing repetitive checks.

Now, if you see a `Maybe Thing`, you instantly know that that thing is either JUST the thing, or it's Nothing, and maybe's type is:

  data Maybe a = Just a | Nothing
Type classes are also amazing, they're basically just as ergonomic as Go's interfaces, without some of the weird hangups and interface{}

All that said, I definitely get the hangup, Haskell is difficult to get started with, even to this day, but man, that hurdle is so worth. Maybe I'm just addicted to high-learning-curve things but Haskell feels good.

Post reply on HN