Grok all the things

grok (v): to understand (something) intuitively.

Erlang

👶  Children (ELI5)

Hello, my little adventurers! Are you ready to embark on a fantastic journey to explore the mesmerizing world of Erlang? Trust me; it's going to be an undeniable whirlwind of fun, excitement, and tons of learning treats.

Erlang is like a magical language that helps computers talk to each other and work together to accomplish amazing tasks! Can you imagine your toys working together to build a fantastic toy castle? That's precisely what Erlang does with computer programs!

🚀 How Erlang Came to Be: The Story of Its Birth 🚀

Once upon a time, in a land far, far away (or, more precisely, in Sweden), there was a company named Ericsson. This company was on a mission to create the most efficient telephone systems in the world.

In 1986, a group of brilliant scientists embarked on an adventure to find the perfect way to make computers more cooperative and better at multitasking. After years of hard work and determination, they came up with the remarkable solution that is now known as Erlang. Named after a Danish mathematician named Agner Krarup Erlang, who loved studying how telephone networks worked, this language has since become famous far and wide!

🧙‍♂️ The Magical Powers of Erlang 🧙‍♂️

Erlang is no regular language – it's got some enchanting powers that make it perfect for managing communication between computer programs! Let's take a peek at some of its fantastic abilities:

🔁 Concurrency – Working Together, Side by Side 🔁

Erlang is like a team of helpful elves that can work on different tasks at the same time. These elves are called "processes," and they can perform multiple tasks concurrently! It's like having many magical helpers working on building your toy castle simultaneously.

Here's a simple example in Erlang, which shows two processes working together to play a game of catch:

-module(catch).
-export([start/0, player1/1, player2/1]).

start() ->
    Player1 = spawn(catch, player1, [0]),
    Player2 = spawn(catch, player2, [0]),
    Player1 ! {self(), hello},
    receive
        {Player2, Done} -> io:format("Game finished!~n", [])
    end.

player1(Count) ->
    receive
        {From, hello} ->
            io:format("Player 1 caught the ball!~n", []),
            if
                Count < 5 ->
                    From ! {self(), hello},
                    player1(Count + 1);
                true ->
                    From ! {self(), done},
                    io:format("Player 1 is tired.~n", [])
            end
    end.

player2(Count) ->
    receive
        {From, hello} ->
            io:format("Player 2 caught the ball!~n", []),
            if
                Count < 5 ->
                    From ! {self(), hello},
                    player2(Count + 1);
                true ->
                    From ! {self(), done},
                    io:format("Player 2 is tired.~n", [])
            end
    end.

In this game, two players take turns catching a ball until they get tired. The start() function sets up the game by creating the two players as processes, and the players communicate by sending messages back and forth.

🔄 Fault Tolerance – When Things Go Wrong, Erlang's Got Your Back 🔄

Imagine if one of your toy soldiers falls over while carrying a block. Wouldn't it be great if another soldier could pick up the block and continue building, rather than the whole castle collapsing? That's fault tolerance! And guess what? Erlang has it too! It helps computer programs recover from errors and keep going even when things go wrong.

🔁 Hot Code Swapping – Changing Clothes While Running a Race 🔁

Have you ever seen a cartoon character change clothes while running really fast? It's kind of like that! Erlang lets computer programs update and change without having to stop and start over. This ability is super useful in situations where you can't afford to stop the program, like in a race or during a phone call.

ğŸŽ The Joy of Learning Erlang: Simple Steps to Get Started ğŸŽ

Now that you've gotten a glimpse of the many wonders that Erlang has to offer, I bet you can't wait to learn how to wield its power for yourself! Here's a straightforward outline to get you started on your journey:

  1. Learn the basics of Erlang: Start by mastering the syntax – that's like learning the alphabet and punctuation rules for our magical language.
  2. Understand concurrency: Discover how to create and manage those helpful elves (processes) we talked about earlier.
  3. Master fault tolerance: Learn how to build robust programs that keep going even when obstacles arise.
  4. Embrace hot code swapping: Find out how to change your programs on the fly without having to stop and restart.

As you embark on this thrilling journey, remember that learning a new language – whether it's spoken, written, or for computers – takes time and practice. But, like any great adventure, the rewards are definitely worth it!

🌈 The Beginning of a Beautiful Friendship: You and Erlang 🌈

And so, my dear friends, I hope this tale has sparked your curiosity and ignited an unquenchable thirst for knowledge! As you venture forth into the enchanting realm of Erlang, remember that the sky's the limit – you're now on the path to becoming a true master of concurrency and fault tolerance!

May your journey be filled with wonder and excitement, and may you always find joy in the boundless world of Erlang!

Grok.foo is a collection of articles on a variety of technology and programming articles assembled by James Padolsey. Enjoy! And please share! And if you feel like you can donate here so I can create more free content for you.