this article is still under development

Functional programming

Developers who use functional programming languages like Javascript are often surprised when they look at Elixir code because it doesn’t look very functional! Instead it looks quite procedural, or imperative. There are just Modules and Functions and to make code work you just call them. Where are all the functional things?

I think the problem is that languages confuse Reactive with Functional. Just because you have to react to an event doesn’t mean you should be passing closures to asynchronous functions!.

Take for example this article:

“Concurrent programming feels just a little bit more imperative than the rest of Haskell, because you compose actions that actually mutate something”.

Imperative is Simpler

In an imperative language code is executed from top to bottom, one statement (expression actually) after another.

For example:

file =!("my_file.txt")
strs = String.split(file, " ", trim: true)
subs =, fn str -> if str == "tom" do "Tom" else "Tom" end)
joined = Enum.join(subs, ",")
Database.write(joined) #just an example
IO.puts "done"

More processes => less reactive code

If Elixir is functional, then where are the callbacks, promises, awaits, etc? In Elixir I don’t care if is run in my process or asynchronous in another process - I need the result of the before I can do the next thing. So I can write code simply and imperatively. What enables this?

Processes (and threads) were invented for two purposes:

  • Wite code simply and imperatively (for humans)
  • Run more efficiently, i.e. concurrently or in parallel (for computers)

In Elixir there really is no difference between concurrent and parallel Anything that is done with processes can either be run concurrently or in parallel with other processes because of immutability and local state. Processes are lightweight and are used like as any other language construct.

Processes use dependent imperative steps to accomplish a task. Imperative code is easy to understand and makes programs more reliable. And you don’t need mutation to do this.

This “style” of programming might have historically been impractical in many contexts, but has suddenly become relevant and practical (Why? See my other Blog _Hint: distributed and parallel are no longer special cases.

Async / await

Continuations in C# can run in any thread. This is the same approach in C++.

I don’t understand this. Now all my logic is broken up to arbitrary places. Why didn’t I just write it on another thread in the first place.


Reactive programming is a nice pattern. However, if you are using Reactive programming as a technique to share threads then you might be overcomplicating the logic.