Oh, Erlang! 🤯

What we did for #SpawnFest 2021

Brujo Benavides
ITNEXT

--

For almost ten years, I waited patiently but actively. And finally, the time has come! I was able to participate again in my all-time favorite hackathon: SpawnFest. In this article, I’ll show how Mariano, Manuel, Tetiana, and I spent the last 48 hours emojifying as many Erlang modules as possible.

Yes, that’s us!

Background

Let me start with a bit of personal history… 👴🏻

Back in 2011, when I was one of the youngest Inakos in Buenos Aires, Chad (or is it Chad?), Manuel, Marcos, and I spent two days locked in a house writing Erlang code for a contest. That contest was the first SpawnFest ever. It was a truly fantastic experience, particularly for people living far away from the leading developer community centers of the world.

Watch this talk by Iñaki to understand what being an Erlang dev in Buenos Aires felt like back then.

We played again the following year. But then, after its second edition, the organizers discontinued the contest. 😢

We waited for a while… ⏲ … hoping to be able to participate again.

Five years later, in 2017, Marcos and I decided to take matters into our own hands: We started organizing the contest. We did it basically from scratch, but we were very fortunate to have many people helping us with it. We organized 2017, 2018, and 2019 editions (the last two with Juan and Darío, too).

It still is one of the most rewarding experiences of my life. I would do it again millions of times if it was only up to me. But I was still longing for the chance to play again. That, plus other circumstances, led us to seek the help of Fiqus to organize the event in 2020. Still, those same circumstances prevented me from building a team and competing in the event. I ended up helping the organizers a bit. 🤷‍♂

This year, we also started looking for other folks to take care of the organization (this time indefinitely) and luckily we found The Fellowship of the BEAM (Pablo, Paulo, Bryan, and Filipe from The Erlang Ecosystem Foundation).

Almost 10 years after the last time, I was finally able to play again! 🎉

BEAMoji 🪄

It took us quite a while to build the team, but from the get-go, we had a very clear idea of what we wanted to achieve in this contest:

We wanted to have fun, not rush

and build something just for the fun of it.

And that’s exactly what we did.
We wrote the funniest rebar3 plugin ever: BEAMoji.

What is BEAMoji? 🤌

BEAMoji is a plugin that adds the rebar3 emojify command, which allows you to turn all the boring atoms in your code into funny, creative, progressive, and (why not?) auto-localized… emojis!

Do you want an example? Say no more…

Do you want to test it yourself? Of course…

Add this to your rebar.config:

{deps, [beamoji]}
{project_plugins, [beamoji]}.

Then update your deps and run…

$ rebar3 emojify

You should see something like this as output…

===> emojifying your code with beamoji_emojilist_translator…
===> emojifying src/your_module.erl with beamoji_emojilist_translator…

Then, your module would’ve changed from… 😑

search(P, [H | T]) ->
case P(H) of
true ->
{value, H};
false ->
search(P, T)
end;
search(P, []) ->
false.

…to… 😱

'🆘👀🍎🌈💿️❤️'(P, [H | T]) ->
case P(H) of
'🦖🌈🦄👀' ->
{'✌️🍎🦙🦄👀', H};
'🔥🍎🦙🆘👀' ->
'🆘👀🍎🌈💿️❤️'(P, T)
end;
'🆘👀🍎🌈💿️❤️'(P, []) ->
'🔥🍎🦙🆘👀'.

…or… 🤩

'👀️'(P, [H | T]) ->
case P(H) of
'✔️' ->
{'⚖️', H};
'❌' ->
'👀'(P, T)
end;
'👀'(P, []) ->
'❌'.

…depending on what translator you decide to use.

Translators 🗣

BEAMoji comes with 3 translators that you can pick using rebar emojify — translator your_favorite_translator. Each of them will turn your atoms into emojis (and back) using a different strategy:

  • EmojiList: This translator is the default one. It has a dictionary of known atoms and it maps each one to a sensible emoji. You can see it in action in the last example above.
  • BaseEmoji: This translator started as something like a Base64 with emojis, but we made it a bit more intuitive along the way. Check if you can find the relationship between the emojis and what they represent! 🕵️‍♂️
  • MultiWords: This translator is like EmojiList, but it can handle multiple words in an atom as long as you write them using snake_case.

Parse Transformation ⏪

Just replacing the atoms with their emojified versions would likely break your code, since many atoms have specific meanings like true, false, undefined, error, ok, etc. Many of them are used as module and function names, too. We couldn’t just emojify them.

To make the emojified modules work we add attributes during the translation to run a parse transform and tell it which translator was originally used so that the parse transform can “demojify” the module before it’s sent to the compiler.

In this way emojis are for humans, the compiler sees the module as if no translation was done. It’s a little secret between you and us. 🤫

Lessons Learned 🤓

Turning words into emojis is not a trivial task. We achieved our goals during the weekend. We even published the project on hex.pm. But we had to work around a few obstacles along the way, and we learned quite a few valuable lessons with those experiences. We detailed them all in the repo. Go check them out! There’re a couple of funny bits here and there.

And we wanted to share this learning experience with everyone. So we want to invite you to keep learning with us. For that, we prepared one of the world-famous CleverBunny 🐇 quizzes. Jump in on it and check your emoji-skills!

--

--