Once it was exiting. Something new. Software opened a whole world for me. Years after it became just a tool. It gets the job done. Today I'm getting to enjoy writing code again. And it's not a new skill or better JavaScript framework (although Svelte is pretty promising).

It's Elixir. A language. I'm more productive. I can't even explain it, I've finally started doing TDD. My code is readable and reasonable. I'm proud of it. It just forces you to think more about what problem you're trying to solve. The language doesn't have shortcuts apart from dynamic typing. That's probably a good thing. "Dializer" the code analyzer does catch a lot of bugs while coding anyway so you get most of the main benefits of static types.

Here's a concrete example. In JavaScript when you need data you need to

  1. fetch the data
  2. check for response.ok
  3. try { to } catch (errors) { when parsing json }
  4. actually put the fetched data where you needed it in the first place
  5. check that the format is good and app doesn't crash

It's enough if's and try's, that devs just skip checkint it all and either risk a crash ("ah, should work just fine") or just try and catch the whole process and get terrible error handling.

Generally you don't really do anything other than print an error somewhere. So why all the extra code? Here's Elixir:

  1. Fetch
  2. put the data to where you need

That's all. Say you're a web spider, scraping the internet for links. If you don't receive the data you discard the query. Doesn't matter if the issue was connection loss or invalid JSON - you just continue with the next task, scraping the next link. If you want you can of course log errors or react to failures. By default there is many times less code.

Elixir is also functional. Variables are immutable. Functions are pretty much pure with the extra impurity so you don't have to learn what a Monad is. I wonder if Agents are basically the same thing anyway.

It's just one of those things that are so good people are suspicious of you when you praise it. Totally a fanboy :)

Here's a flaw: global variables. Yeah there's namespaces, but you still need to find out in which file the module is coming from. There's shit like use Module that magically inserts functions and macros into your module so if you're using 3 use commands you have no clue from which library your functions are from. It's not the end of the world, but if a tutorial is confusing to read for a 6-year experienced programmer, then I'm sorry I think you're just hiding valuable information. Node.js the perfect example where there is never any doubt where something is from. Any variable in your file is always exlicitly traceable in that same file.

I tried using the most popular CouchDB library recently. The developer of that library thought it was a good idea to have 10 different all-over-the-app-global variables in my app. And it didn't think it to be necessary to mention in the docs how to use this library. This is insanity! This was an erlang library however, maybe that's why? I guess I need to rewrite it... I just wish if I choose a restricting language to have better quality - it would actually be reasonable enough to not rely on globals this much.

Yet I still love it.

A functional language is great, because you don't leave state laying around your software. State is always a separate place in a very clearly defined environment. Think about it this way. Your code will always do what you ask it to - if you give it data it's built for. If the data has an unexpected shape or content, your app starts leaking. So state is dangerous. That's what makes programming complex. This is also why orchestrating objects in OOP languages is an unneccessary complexity (and a pain, IMHO). OOP tries to abstract complexity with another layer of complexity. FP tries to keep everything as simple and foolproof as possible.

In JavaScript I sacrifice code quality for development speed. In Elixir my sacrifice is globals, but curiously I do get stability and perhaps even more flexibility since the limitations of the language helps me think better, cover more usecases with less code.

I can't tell anyone to try it (you wont if you already haven't), but I would still suggest to make a prototype app with it for mental excerice.