News for hackers. Stuff that matters.
Re:Core Erlang by Example by jkingsbery on Monday May 07, 2018 @09:40AM (#17012597)
That reference helps the original link make a lot more sense.

I've spent about 2.5 years of my career writing Erlang code. It's statements like "Core Erlang is less complicated than Erlang" that always trouble me about the Erlang community - Core Erlang is less complicated for compilers, not for humans. In this first in a series of blog posts about Core Erlang, there is no context given around what it is or why anyone should care.

Erlang is a great language and environment, but it really struggles with the marketing aspects of a platform, that is, how to make it accessible to humans.

Re:Core Erlang by Example by jacquesm on Monday May 07, 2018 @09:57AM (#17012724)
It's a hallmark of slow moving platforms: the investment in time is such that by the time you need something like Core Erlang you will know exactly where to place it. Erlang is not exactly beginner friendly (in spite of some effort in that direction) and it is a strange beast in many ways compared to what counts for 'modern'. Even so it has stood the test of time well and embodies a lot of the things that people are - reluctantly - rediscovering in its foundation rather than as belated add-ons.
Re:Core Erlang by Example by bobwaycott on Monday May 07, 2018 @11:18AM (#17013359)
I think Erlang as a language is relatively friendly, even to some beginners. OTP, of course, is where the challenge lies.
Re:Core Erlang by Example by dmix on Monday May 07, 2018 @11:31AM (#17013493)
Agreed, Erlang is surprisingly simple and concise. It's pretty straightforward how you'd design any particular piece of code.

The only complexity is figuring out OTP, which in itself is very easy to use, but you must understand all the underlying abstraction it's masking before really being good at it.

Once you get familiar with the boilerplate of distributed systems and see how OTP helps eliminate much of it, with a best-practice design figured out for you, that's when you really start to respect Erlang.

Of all the languages I've learned on the side I think Erlang/OTP has the most amount of features I feel are missing from other languages (proper pattern matching being the biggest).

Re:Core Erlang by Example by vram22 on Monday May 07, 2018 @02:09PM (#17014957)
How does F#'s pattern matching compare to Erlang's?
Re:Core Erlang by Example by klibertp on Monday May 07, 2018 @03:00PM (#17015438)
They're similar in what they are used for, but they come from different traditions and so have some differences.

F# patterns come from ML, with active patterns added on top. Erlang patterns come from Prolog, with unification removed.

A quick example, in Erlang you can write:

   1> (X = {1 = A, [2, 3]}) = {1, [2, 3]}.
   {1,[2,3]}
As well as:

   1> ({A = 1, [2, 3]} = X) = {1, [2, 3]}.
   {1,[2,3]}
That is, the `=` is actually a pattern matching operator and the order of its two operands doesn't matter (well, not really, not everywhere - that's where the "removed unification" comes from - but close enough). That's because in Prolog the `=` operator denotes actual equivalence, not an assignment, and Erlang inherited that.

In F# and OCaml this is done with a special operator, `as`, and it cares about the order of its operands very much. You can do this:

   > let (1 as a, [2; 3]) as x = (1, [2; 3]);;
   val x : int * int list = (1, [2; 3])
   val a : int = 1  
but

   > let (a as 1, ...etc
obviously won't work.

All in all, both mechanisms work quite well and you can translate between them easily, but they are not 100% equivalent. Erlang has much simpler syntax (it's basically just `=`) while F# adds `as`, `&` and other constructs. In Erlang, once a name is matched with an expression, it is equivalent to that expression and stays that way forever. In OCaml, you can readily reassign matched names. That also makes Erlang pattern matching act like an assert and (identity) comparison in some situations, which are both different things in F#.

So, the use-cases are very similar, but the concepts underlying the mechanisms differ which in turn makes some details of the mechanisms differ too. Both are a joy to work with, to be sure, compared to the "applied ifology" or the dreaded `switch` statement, though :)

Re:Core Erlang by Example by dmix on Monday May 07, 2018 @04:19PM (#17016150)
Yep, Erlang's use of = operator's pattern matching / assignment allows for some very elegant solutions, in addition to function guards, deconstruction, and other use-cases.

It basically uses pattern matching as a fundamental/primitive part of the language design, rather than some useful add-on or tertiary feature.

Re:Core Erlang by Example by patrec on Monday May 07, 2018 @04:58PM (#17016439)
The flipside is that in Erlang often need repetitive code like so:

      case X of
         {expense, N} -> Total - N;
         {invoice, N} -> Total - N;
         {loss, N}    -> Total - N;
         {credit, N}  -> Total + N
       end
         
whereas in ocaml (and F#, modulo details) you could just do something like:

      match x with 
          | (`expense, n) | (`invoice, n) | (`loss, n) -> total - n
          | (`credit, n) -> total + n;;
The examples are unidiomatic and artificial and you can sometimes ameliorate it with guards, but it's a frequent (minor) annoyance.
Re:Core Erlang by Example by marci on Tuesday May 08, 2018 @05:55AM (#17019855)
Close enough?

  case X of
    {Cat, N} when Cat == expense; Cat == invoice; Cat == loss  -> Total - N;
    {credit, N}  -> Total + N
  end
Re:Core Erlang by Example by klibertp on Tuesday May 08, 2018 @02:33PM (#17023430)
patrec said that

> you can sometimes ameliorate it with guards

which is exactly what you did, so I don't think you're disagreeing here :)

Re:Core Erlang by Example by rdtsc on Monday May 07, 2018 @11:21PM (#17018572)
That's a neat pattern in F#, I like it!

In Erlang's case (pun intended!) I'd probably go for a function though:

    total({expense, N}, Total) -> Total - N;
    total({invoice, N}, Total) -> Total - N;
    total({loss, N},    Total) -> Total - N;
    total({credit, N},  Total) -> Total + N.
Re:Core Erlang by Example by klibertp on Tuesday May 08, 2018 @05:38AM (#17019812)
That still repeats the `Total - N` 3 times, though. As patrec said, it's possible to work around this with guards in this specific case, but in general this kind of duplication is indeed common in Erlang code. You can avoid it many cases by correctly factoring the code, but it's not always possible and then it's a bit irritating. Not too much, though. It's basically the difference between fall-through and non-fall-through `switch` statement: OCaml/F# allow fall-through (as an option, not by default, thankfully), Erlang/Elixir/LFE don't.
Re:Core Erlang by Example by vram22 on Monday May 07, 2018 @06:32PM (#17017012)
Thanks for the detailed answer.
Re:Core Erlang by Example by djsumdog on Monday May 07, 2018 @10:20AM (#17012934)
I started playing around with Elixir a while back and find it really fascinating as a language.

I've been a Scala dev for years and I gradually learned FP by moving from Java to Scala, but in the case of Elixir, I've only barely looked at some Erlang previously.

Would you say Elixir has done a better marketing job of being accessible to developers?

Re:Core Erlang by Example by pdimitar on Monday May 07, 2018 @11:28AM (#17013459)
Elixir has pretty solid marketing indeed but IMO the tooling is what really makes it shine. Hex and Mix are the simplest, cleanest and most straightforward tools I ever used for 16 years of career. Add OTP, friendly syntax and mature runtime to the mix and IMO Elixir is right now unbeatable in the realm of dynamic compiled languages.
Re:Core Erlang by Example by andy_ppp on Monday May 07, 2018 @11:05AM (#17013275)
Marketing is better than Erlang (not difficult: http://erlang.org/doc/man/lists.html), but also it stacks up to some analysis rather than just being hype. Largely due to it being based on Erlang but also developer friendliness (build tool, docs, security, setup, simplicity) is really second to none for a compiled language.
Re:Core Erlang by Example by ch4s3 on Monday May 07, 2018 @11:41AM (#17013603)
I think it's not so much marketing as developer experience, and tooling. As a sibling post mentions, Mix and Hex are amazing. Mix new is a very nice gateway into a new project, giving you a fully working setup and even setting up the basics of a supervision tree, if you want it. Beyond that, it makes some less approachable aspects of OTP much simpler for a newcomer to use. Once you get the basics, Genservers are very nice to work with.
Re:Core Erlang by Example by klibertp on Monday May 07, 2018 @03:21PM (#17015630)
The stdlib is also a strong selling point of Elixir. Agent and Task modules are a nice addition. AFAIK they have no equivalent in Erlang stdlib. It's trivial to implement them on top of gen_server, but that's it - you need to reimplement them every time, while in Elixir you have them available by default. DynamicSupervisor is similarly a nice(r) interface to simple_one_for_one supervisors.

In terms of language features, Elixir gives you (almost first-class) modules, protocols, and macros. They are all implementable in Erlang, for example qlc is a DSL implemented with parse transforms (which are macros), but Elixir gives them to you nicely packaged and ready to use.

It can also become a problem. I love Lisps, and love proper macros, but every other macro I see written by Elixir guys makes me cringe. Macros are a powerful tool and it takes time and effort to learn not to abuse them. In Lisps, even the younger ones, like Clojure, people only write macros if there's really no other way to do something. In Elixir, people write them for everything, they break hygiene habitually, and the language encourages that (the `use` and `__using__` are the biggest offenders here, IMHO). It's a trade-off between easy-to-write (in Elixir) and easy-to-read-and-debug (in Erlang). Both approaches are valid, but for different use-cases.

Re:Core Erlang by Example by weatherlight on Monday May 07, 2018 @10:47AM (#17013120)
Absolutely.
Re:Core Erlang by Example by bitwize on Monday May 07, 2018 @07:53PM (#17017510)
I'm not sure I've encountered a context where "less complicated", said of software, implied "easier to use". Siri is fiendishly complex but very easy to use. A brace and bit is less complicated than a power drill, but the power drill is easier to use.

Also, please don't use rhetoric of the form "We need to make software accessible to/usable by humans." If the software is not usable by humans, who exactly is using it? To what species do they belong? Say "new users"/"people unfamiliar with the language"/etc. instead.

This blog entry is part of an ongoing series about the passes in an Erlang compilation. The author probably assumed some familiarity with Erlang itself, and previous entries in the series, not intending this entry for an audience of general unspecified humans. I'm not sure it's the author's duty to turn every technical post they write into newbie-accessible marketing.

Re:Core Erlang by Example by accnumnplus1 on Monday May 07, 2018 @12:14PM (#17013917)
But that's what he said: "Core Erlang is less complicated than Erlang, and is therefore more suited than the abstract format for code analyzing tools (such as Dialyzer) and optimizers."
Re:Core Erlang by Example by bitwize on Monday May 07, 2018 @07:56PM (#17017535)
If you're a human, you understand that "less complicated" means easier to use. Since you're a software engineer you must be some sort of bioengineered alien hybrid, for whom words don't hold the clear indisputable meanings they do in the Imperium of Man.