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.

NobbZ

NobbZ

For a general comparison of language and how to use it, it is sufficient, as soon as you replace the singlequotes by doublequotes in the io:format examples.

leifericf

leifericf

Thanks for the tips!

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement