leifericf

leifericf

Code snippets to compare Erlang and Elixir syntax

Hello, friends!

Context:

As you might know from this thread, I’m working on a presentation.

Following a tour of Erlang history, I have a slide which reads:

“If Erlang is so great, then why should I bother with Elixir?”

On the following slide, I mention that Erlang has a somewhat alien syntax, since it was influenced by Prolog and Smalltalk. New programmers can find that scary and off-putting.

I go on to mention that one of the reasons to choose Elixir is that the syntax is more modern, familiar and user-friendly than its big brother, Erlang. I mention that is feels kind of Ruby-esque. Of course, I also point out that Elixir only looks like Ruby on the surface and that it is fundamentally different.

Problem:

In order to make this comparison more immediate, I would like to show some semantically equivalent code-snippets from Erlang and Elixir, side-by-side. They need to be short enough to fit on one slide.

Some of the attendees have never seen Erlang or Elixir code before. I have not shown any code examples up until this point in the presentation, as it is very high-level.

I’m struggling to come up with some good examples that show off the differences between Erlang and Elixir. Preferably, it would highlight some unique features as well, e.g. pattern matching.

Question:

Could I ask for your help? If you wanted to illustrate the syntactical differences between Erlang and Elixir, what do you think would be some good (and terse) examples?

I will also refer to this forum thread in my presentation, so attendees can see more examples.

Marked As Solved

leifericf

leifericf

After a few hours of Googling, I discover that we have this page on the official website :joy:

That’s pretty much exactly what I was looking for.

But if you have any other examples, I would gladly take those as well!

Also Liked

leifericf

leifericf

For the curious, here is the comparison slide I ended up with:

I might change it or add a few more.

gregvaughn

gregvaughn

I’m not sure how much Smalltalk influence there is in the syntax. Prolog is the main influence I’ve heard about.

One other thing that might fit on the slide is to have a second clause for some_fun/1. In Erlang you’ll need to separate the clauses with a semi-colon, but Elixir has no explicit syntax for that.

NobbZ

NobbZ

This slide does not only compare syntax. It also swaps out functions from the stdlibs.

Additionally you use atoms (single quotes) on the erlang slide, where you should use strings (double quotes).

And IO.inspect is more like using ~p in :io.format, as ~s will fail with badarg when given a tuple, while IO.inspect will happily print it out. Also a noteworthy difference is, that :io.format returns :ok, IO.inspect returns the inspected value.

Last Post!

leifericf

leifericf

Ah, nice—Thanks! I haven’t seen that one yet.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement