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.

Where Next?

Popular in Questions Top

lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Tee
can someone please explain to me how Enum.reduce works with maps
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
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
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New

We're in Beta

About us Mission Statement