Fix Elixir

Elixir is too complicated.

Elixir needs to be fixed.

I think we can all agree with these notions. Have you seen the Elixir-lang mailing list lately?

Having used it for a couple or three weeks, you realize it requires far too much typing — that is, pounding away on the keyboard with your fingers. What it truly lacks is typing — the kind that pre-defines a variable’s content type. We’re going to talk about fixing that shortly.

In this article, I hope to make a few suggestions to fix Elixir to make it better for future generations.

Steel Workers on a construction site to fix Elixir
If you need a change in your infrastructure, try a steel worker. Or three. They can fix Elixir for you.

Elixir Needs Types

For starters, we need to differentiate between data types. But we need to keep this simple so people will use it. I propose three types: Strings, Associative Arrays, and Lists. For simplicity’s sake, we’ll define numbers as strings, also. This doesn’t make sense, but it’s convenient and quick. Also, these types are more about the structure of the data than the contents of them. A string, thus, is a single unit of data without any sort of structure around it.

Current maps are far too complicated with far too many ways to do the same thing. Aren’t we all tired of looking for a value for a particular key by typing in this mess:

iex> example_value = Map.fetch(example_map, example_key)


Why not just have:

iex> example_value = example_map{example_key}

It’s so much more direct.

Fixing Strings

Strings are too complicated. I think we’re all tired of typing in “Hello” and getting back a result like:

iex> "Hello"
[67, 63, 70, 70, 72]

(No, it doesn’t actually do that in iex. This is a dramatization, like that time Dateline NBC blew up pick-up trucks, OK?)

Why not just learn Assembler at this point?

Let’s Unicode all the things and make them all just plain strings, composed of lists of characters.

Separating the Data Types

We need something short and pithy that gives us an easy visual reference to a variable’s data type. Because, right now, in Elixir, map_example could just as easily be a valid map, string, integer, or process id. MADNESS! We all know you can’t trust programmers to name things.

The solution is simple. Use a sigil. Elixir has a few leftover, but I say we just need to go all the way and use whatever we can. Let’s stick with an “S” for a string, an “A” for a list since it’s so similar to an array, and, er, we’ll use an “H” for an Associate Array, which is the same thing as a Hash.

Now, it might be confusing to use letters, so let’s use special characters. The “S” looks a lot like a “$”. The “A” can be an “@”. The “H” can be “%”, which is a bit of a stretch, but I’m running out of options here already. Prefixing with “|-|” wouldn’t work as it looks a bit like a pipe, and we might need that for all the multitudes of changes the pipeline operator needs. (That’ll be a future post.)

This also makes string interpolations simpler. We don’t need that ridiculous #{} muddying up our beautiful list of Unicode characters anymore. "Hello #{variable_for_world}" is now the much simpler "Hello $variable_for_world". Plus, your left pinky finger hits shift two less times now.

More Minor Changes

Using “<>” to concatenate strings is the most baffling design decision in the history of computer programming. They don’t do that in C, so why would any language do anything different? Everything should be based on C, just like every command line should look like it comes out of a Unix box. Even Microsoft is using Gnu BASH now…

We’re not going to use “+” for that, because we’re better than Javascript and we’re working on clearing up the differences between strings and integers here. I don’t want to overload the operators. Just the variables.

We’ll pick something sane here. In fact, I’ll give you a couple of options: “.” and “,”. Those make sense.

Tuples are dead. They are replaced with arrays/lists. If you like {:ok, “All is good”}, you’re going to love a two element array with those values. If you want to know if the function was successful, just ask for the first element of your list:

iex> @results = ("ok", "All is good")
iex> List.first(@results)

Or, just plain old:

iex> @results[0]

Everything in life should be zero based. You can’t spell foist without an 0, amIrite?

Summing It Up (So Far)

In these three short steps, we’ve already fixed strings, typing, and visual identification of types. We’ve cleaned up Elixir for the programmer, not touching on OTP at all.

I’ll be submitting pull requests on all of these items momentarily.

M. Night Shyamalan, The Programmer

Congratulations, you’ve just fixed Elixir by turning it into Perl.

Kinda almost like Perl6, actually. Perl has a couple of web frameworks, too, you know. Perl Dancer and Mojolicious can help.

You’re welcome.