Erlang Battleground
Funny & Weird Stories found while coding on the BEAM

690 Followers
·

y la arquitectura de una aplicación Web

Tecnologías y lenguajes existen muchos, pero ninguno como Erlang para desarrollar un sistema completo. Como Joe Armstrong dijo, “si Java es ‘hazlo una vez y córrelo donde sea’, Erlang es entonces ‘hazlo una vez y córrelo para siempre’ ”.

Image for post
Image for post

El Inicio

Hace mucho tiempo, por azares del destino, me topé con el maravilloso mundo de las computadoras. Inicié programando con Cobol, aunque me hubiera gustado empezar desarrollando en el lenguaje C, por su sintaxis y eficiencia.

Tandem Computers

El camino que me llevaría a encontrarme con Erlang comenzó cuando conocí la tecnología Fault Tolerance in Tandem Computer Systems, tanto en hardware como en software. Sin ahondar en detalles, En Tandem, los programas se desarrollan de manera separada, por un lado, los requesters y por otro, los servers — algo muy similar al frontend y el backend de la tecnología Web — , para poder configurarlos en Pathway de manera distribuida entre todos los CPU’s de la computadora. …


Or how to use Pattern-Matching for Tests

While acting as a mentor on the FutureLearn MOOC about Erlang I presented an idea that folks like Adolfo Neto loved (he even tweeted about it 🧡). It is, in fact, the way I introduce people to pattern-matching when I’m teaching them Erlang. It’s a way to write tests that let you naturally work your code out from them… Sounds familiar? Yes! It’s Test-Driven Development!

Image for post
Image for post
Airplane! (1980)

The Process

I learned TDD when I learned Smalltalk. It was such a life-changing lesson! And Smalltalk was the best environment to learn it since it’s built for it. In Smalltalk, I believe it’s actually harder to write code with a different process. If you didn’t try it already, you definitely should! …


Particularly for Erlang

Image for post
Image for post
Good Will Hunting (1997)

So, I Gusti Ngurah Oka Prinarjaya was reading Joe’s Book and he found one of the most amazing examples of List Comprehensions I’ve ever seen…

perms([]) -> [[]];
perms(List) -> [ [H|T] || H <- List, T <- perms(List--[H]) ].

Output:

1> lib_misc:perms("123").
["123","132","213","231","312","321"]

And, of course… he couldn’t understand it. …


Let’s go back to the origins of this blog with a bit of unexpected code behavior. This time, let’s try removing elements from a list…

Image for post
Image for post
Maxwell Smart — because I couldn’t find any proper image for this article

Let’s Subtract!

The beauty of this trick is that the code examples work in both Erlang and Elixir, with barely any changes at all… I’ll do it in Elixir, feel free to try them out in Erlang or efene if you like.

Now, this is a list…

iex(1)> [1, 2, 3]
[1, 2, 3]

And now, we can subtract a few elements from it…

iex(2)> [1, 2, 3] -- [1, 2]
[3]

Let’s now subtract that last one…


…or Why you should use specs if you use opaque types

Following the steps from Devon and Stavros, I wanted to write this article to highlight a not so obvious dialyzer lesson about opaque types and specs…

Image for post
Image for post
Help me help you — Jerry Maguire

TL;DR

For the impatient ones…

If you define an opaque type, you have to add specs to all the exported functions that use it (i.e. your module’s API).

Opaque Types

Since this article is about opaque types, I will do a quick intro first…

In Elixir, there are 3 ways to specify a user-defined type:

@type t1 :: boolean | atom # this type is exported
@typep t2 :: String.t …


…for Erlang & Elixir

A few months ago, Fred gave me a copy of his latest book (Property-Based Testing with PropEr, Erlang, and Elixir) so I could review it. So, here I am, returning the favor. But I’ll also use this chance to express some of my feelings and opinions about Property-Based Testing in general, since reading the book elicited quite a few of them. This will not be one of the usual articles on this blog, but I hope you’ll enjoy it anyway.

Image for post
Image for post

The Book

In a nutshell, this book is a very extensive and detailed manual/hands-on-tutorial with which you’ll first learn the general concepts behind Property-Based Testing (e.g. properties, generators, shrinking, etc.), then you’ll learn the basics of the methodology and tools and finally some of the more advanced techniques like custom generators, stateful properties and more. …


I remember around 2008 when I was submerged in the Java world I had a change to try awesome caching libraries and frameworks, such as: Hazelcast, EHCache, Spring Caching, etc. …


A while back this question popped up in one of the many places where the Erlang community gathers, I think it was IRC:

How many functions do you have in your Erlang node?

As an answer, Craig posted this beauty:

1> length([{M,F,A} || {M,_} <- code:all_loaded(), {exports,Fs} <- M:module_info(), {F,A} <- Fs]).
2531
2> length([{M,F,A} || {M,_} <- code:all_loaded(), {exports,Fs} <- M:module_info(), {F,A} <- Fs]).
2539
3> {ok,2}.
{ok,2}
4> length([{M,F,A} || {M,_} <- code:all_loaded(), {exports,Fs} <- M:module_info(), {F,A} <- Fs]).
2628
Image for post
Image for post
Original from KissPNG

What’s going on here?

As usual, it’s better if you try understanding this by yourself. If you are up for the challenge, just boot up an Erlang VM and try to figure out what’s happening. …


The year was 2008. I had a steady job as a .NET developer. Then I read an ad from a company that was looking for developers with knowledge of Erlang… or functional programming in general and I applied.

I had learned a bit of Haskell in college and I loved it but I was not even remotely close to having experience in functional programming. Nevertheless, something told me that it was the right path.

Totally unprepared but ready to just improvise and see, I arrived at Novamens for an interview. I met Juanjo there but, more importantly, I met Erlang!

And that moment changed my life. …


Or The Semantic of Function Arguments

Reading ErlangExplained I noticed something that made me question my understanding of The Hitchhiker’s Guide to the Galaxy and also made me think about the way we choose our function clauses.

Image for post
Image for post
Original — by Stmed.NET

What I wondered was how to interpret the phrase “the Ultimate Question of Life, The Universe, and Everything”. In other words: would the Ultimate Question be a question about three combined but independent entities (i.e.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store