Hacker News new | ask | show | jobs
by giancarlostoro 1981 days ago
I'm going to butcher my question so my apologies, I've heard Perl described as a sort of linguist / grammatical type of language, where you can solve the same problem using multiple approaches and syntax. Is this something Raku is drifting from or embracing? I think Raku is kind of interesting and I did try it out a few times whilst it was called Perl 6, but I'm not sure what its niche is. I mostly do Python for professional projects but don't mind experimenting with other languages.

I guess what I'm trying to ask is what are the major fundamental differences between the two languages? Features aside, although if some features are part of the answer thats fine.

6 comments

> I've heard Perl described as a sort of linguist / grammatical type of language, where you can solve the same problem using multiple approaches and syntax. Is this something Raku is drifting from or embracing?

Very much embracing – "turning up to 11" might be a better way to put it. I recently wrote a three-part blog series[0] about what Raku's primary values, and the more-than-one-way-to-do-it idea features prominently in that list.

[0]: https://www.codesections.com/blog/raku-manifesto/

Raku definitely embraces multiple approaches and syntax, continuing the “There is more than one way to do it” motto of Perl. In addition, Raku aims for consistency and composability while introducing new language constructs like laziness, gather/take, async/await, hyper operators, grammars and more.
There are a TON of experiments and language mash-ups in Raku. Let's see here.... Types can include guard clauses that are evaluated at runtime. Typed multi-dispatch on top of that. In addition to normal "sets" it has "junctions", like some sort of funky quantum superposition or something. In theory those can be made parallel at some point. Stuff like that.

One that is particularly funky is the "whatever-star". This is a "" char that can be used in a few places to mean more or less... whatever. For example:

    <4 5 6 7>.map(-> $x { $x + 7 }) # result: (11 12 13 14)
That stabby inline lambda there can be sugared down in a lot of ways, including with the whatever-star:

    <4 5 6 7>.map(* + 7) # result: (11 12 13 14)
... I've not seen anything quite like that in other languages, not sure if it is a new invention or if only nobody else is crazy enough to try it. And yes, you can use multiplication next to it to make it look crazier:

    <4 5 6 7>.map(* * 7) # result: (28 35 42 49)
(also yes, (
* *) will take two inputs and multiply them.)

I will note though that dwelling on these crazy/fun edge cases is amusing, but programs can look quite a bit more like a basic ruby app (with sigils) if you so desire.

Scala has something similar with "placeholder syntax for anonymous functions", where

    _.methodname()
or

    _ + 1
is equivalent to

    x => x.methodname()
or

    x => x + 1
https://www.scala-lang.org/files/archive/spec/2.13/06-expres...
For single placeholders I prefer the look of either the `_` syntax or the alternative some PLs have of `.`.

But otoh, Raku nicely stretches the approach to both zero and multiple placeholders:

* The zero placeholder `.methodname` in Raku is the same as Scala's `_.methodname`

* Any number of placeholders are allowed, so one can write eg `* + *` as an anonymous binary add function.

Note that HN's formatting ate several of the * in the comment above, which makes it much harder to follow.

> (also yes, (* * *) will take two inputs and multiply them.)

That's true, but Raku also supports non-Unicode math operators, so the more idiomatic way to write that would be

  (* × *)
which, in isolation, still isn't that clear. But it usually is in context. And, if it isn't – well, that's why there's more than one way to do it!
XPath has such a thing:

     (4, 5, 6, 7) ! (. + 7)
Imo, while both Perl and Raku are exemplars of extensible PLs in their own ways, Perl's approach is essentially a tower of hacks built on the wrong foundation while Raku's core concept[0] is built to last for decades, if not a century[1].

[0] https://gist.github.com/raiph/849a4a9d8875542fb86df2b2eda892...

[1] https://thenewstack.io/larry-walls-quest-100-year-programmin...

As someone who wrote a limited amount of Perl 5 before writing a not insignificant amount of Perl 6 (now Raku), I find Raku syntax to be deeply Perlish while also being more modern and internally consistent than Perl 5.

IMO Raku has three standout features:

1. Grammars in the stdlib [1]

2. The absolute most flexible multi-dispatch system of any programming language [2]

3. The best regex syntax of any programming language [3]

In 2015, I had to write a DSL for a double-entry accounting system. That's when I discovered @jnthn's Perl 6 grammar debugger [4], which allowed stepping through a Perl 6 grammar line by line and visually seeing how the grammar was consuming a string. At that time I had very little programming experience, which made Perl 6 far and away the easiest way to write a custom DSL parser.

If you enjoy Erlang/Elixir multi dispatch, e.g.

    def format({:ok, %HTTPoison.Response{body: body, status_code: 200}}) do
      body
      |> Meeseeks.parse(:xml)
      |> Meeseeks.all(xpath("/*"))
      |> Enum.map(&Meeseeks.tree/1)
      |> _format
    end

    defp _format([{"current_observation", _version, current_observation}]) do
      current_observation
      |> Enum.map(&_format/1)
      |> Enum.filter(& &1)
      |> Enum.into(Map.new())
      |> Poison.encode!()
    end

    defp _format({"credit", _, [credit]}) do
      {:credit, credit}
    end

    defp _format({"credit_URL", _, [credit_url]}) do
      {:credit_url, credit_url}
    end
Raku does that in an even more flexible manner, destructuring included. I love how declarative it makes the code read.

However, I must say I've left the honeymoon phase of Raku far behind me now. In my experience, Raku grammars are insanely slow: at least as of many years ago, it was taking ~40 minutes to parse a ledger-style accounting format log file that wasn't even very big. When jnthn's grammar debugger got really buggy and less actively maintained, that defeated one of the biggest reasons I had to use the language. I've also experienced numerous bugs with Raku's type system, and just in general wouldn't write many things in Raku.

But to your question — I would write even less things in Perl 5. I have no use for Perl 5 now that Raku exists, and don't know why anyone would write Perl 5 in the modern day given how many other compelling options exist in its niche. Raku is different, and it deserves to see top caliber core development. It doesn't have that yet, and that's sad.

Frankly Raku isn't capable of replacing really any mature programming language for anything but informal scripting tasks where you don't care about speed, and where you don't need an “academic” tier type system. For those tasks, it is quite a fun language. I remain optimistic about Raku's future, and would seriously question the conventional wisdom of using Python or JS in its place for many, many things.

[1]: https://github.com/atweiden/config-toml/blob/master/lib/Conf...

[2]: https://github.com/atweiden/txn-remarshal/blob/master/lib/TX...

[3]: https://docs.raku.org/language/regexes

[4]: https://github.com/jnthn/grammar-debugger

[4]: https://vimeo.com/32044632

> When jnthn's grammar debugger got really buggy and less actively maintained, that defeated one of the biggest reasons I had to use the language.

I created a couple PRs for the grammar debugger, one that fixed a bug, another that dramatically sped it up, but neither were merged. But imo that was appropriate; spending time on that debugger wasn't a good use of his time.

And now jnthn's work on grammar debugging in Comma is so vastly superior to the old debugger that it would imo be especially silly of him to use up his limited time continuing to pay attention to the old code. I'm curious whether you agree with that?

> Raku is different, and it deserves to see top caliber core development. It doesn't have that yet, and that's sad.

I agree it needs more than jnthn, but surely you agree that jnthn is top caliber?

He has a degree in CS, specializing in PLs, compilers, and VMs, so exactly the right focus for his core dev work. And the university he did his degree at was Cambridge, one of the world's top universities, especially in CS. And he was awarded the degree with honors.

In addition, he is a highly successful, highly paid enterprise systems consultant whose work on Rakudo in his limited spare time, in recent years augmented by occasional grant supported projects that pay less way less than his commercial rate, has always struck me as extraordinarily good.

I've always thought it would be wonderful to have two jnthns, but that we have to respect and appreciate what resources we do have, and let him work at a pace that doesn't burn him out while he continues to mentor the other core devs, as he has now for many years.

Would you say I'm missing something?

Thanks; as someone whose three favorite languages include Perl and Erlang, this gives me more reason to look at it.
a few years ago damian conway made a few talks about the raku first-class grammar objects, it kinda signals no departure from the linguistic interests of that community.