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.

When Elixir Transpiles to Perl6…

The problem with outlets like Slack and Twitter is that they’re ephemeral. Information goes there to die. It’ll never be found again after about 24 hours.

It has been suggested that folks using those outlets to discover things should report them back on their blogs or somewhere more permanent.

I think that’s a great idea, so I’m preserving this discussion here on my blog for eternity. (Or until I fail to pay a hosting bill…)

I asked on Twitter the other day what we’d call a project that converted Elixir code into Perl6 code. Forget ElixirScript; what’s the transpiler to Perl6 going to be named?

  • I suggested Elixerl, which would be dang near impossible to pronounce without biting a cheek or something.

  • Onorio Catenacci suggested Perlixir, which I liked even more.

  • Lew Parker floated a test balloon with Perlix. Like any good piece of Perl coding, it has the advantage of using fewer characters.

  • Luke Imhoff suggested “Mantle”. Why, you ask? “The part of a clam that ‘licks’ a pearl to make it bigger is the mantle, so I propose Mantle so it has to be explained.”

I can’t argue with him, and I also like the word play.

Now, let me be on the record with this: I have no plans on writing something to move Elixir code to Perl6. This is strictly hypothetical. Unless you want to write such a thing. I wouldn’t know where to start…

Perl on the Rebound?

Is this the beginning of a trend — people from other languages recognizing Perl’s accomplishments? Or just a coincidence?

And, finally, just because I thought it was cool, here’s a Perl/Ruby Quote of the Year:

Near Miss

In my third year of college, I took a Programming Languages course that pretty much defined my career.

The class was broken up into groups of four or five people, and each group had to pick a different programming language to study. (Presumably, we reported on that language back to the rest of the class. I don’t remember, but it’s probably what happened…)

I joined a group that would study Perl. This was 1996/1997. Perl would have been fairly popular at that point, being the tool the web ran on after basic HTML.

I fell in love with Perl. Of course, having previously studied languages like Scheme and C and Pascal, of course Perl would look and sound beautiful. It was powerful and easy to read, with lots of creative opportunities for a programmer.

For Christmas that year, I got the Perl Black Book and a CD with a Linux distribution on it. (I think it was Slackware, the world’s worst version of Linux to attempt to put on a computer for a newbie.) Even after the class was over, I could play with Perl on my own.

Years later, I found an opportunity to insert Perl into some client work I was doing and it quickly became my thing at the company.

Looking back, I don’t remember much else about that programming course, aside from the professor being a temporary prof who put all her notes on one long HTML slide that she’d share with the class… eventually. But I do remember that one of the other languages I could have chosen to study that semester had a ridiculous sounding name.


Part of me looks back now and wonders if I had chosen a different group in that class back in 1996/1997, would I have glommed onto Ruby earlier and been a Rails programmer, instead?

Missed opportunity?

How to 'Save' Perl

Curtis “Ovid” Poe answers a Quora question on how Perl might make a comeback.

An excerpt:

One issue Perl has had has been marketing. We’ve done a great job marketing Perl internally the past few years and have really done a great job improving the language and the community, but now it’s time to make that push to the outside world. Many people are completely unaware of how vibrant the community and the language are.

As if to answer that, The Perl Foundation announced “an increased commitment to marketing and public relations” by bringing in a public relations group to help. Don’t know how much programmers will listen to a PR pitch, but it couldn’t hurt…

Back to Ovid:

The other feature is a proper Metaobject protocol in the language (not just in Moose). There’s been some work on this and if it ever gets into core (and Ricardo Signes, the person currently overseeing development on the Perl 5 core, said he’ll put it in if it’s stable), then Perl’s object-oriented features will not only catch up with most other languages, but will leap-frog many of them. However, without communicating this effectively to the outside world, this will be a beautiful gift that most will never open.

Adding in OO to core would be huge and is a necessity, I think. Will it save the language? I don’t know, but it’s a darn good idea and overdue.

Ruby: More Echoes of Perl

David Cross’ book “Data Munging With Perl” came out in 2001. It’s out of print now, and available in its original PDF form free from its author.

Check out this excerpt from the book’s preface:

Over the last five years there has been an explosion of interest in Perl. This is largely because of the huge boost that Perl received when it was adopted as the de facto language for creating content on the World Wide Web. Perl’s powerful text manipulation facilities made it an obvious choice for writing Common Gateway Interface (CGI) scripts. In the wake of the web’s popularity, Perl has become one of the hottest programming languages current in use.

Unfortunately, a side effect of this association with CGI programming has been the popular misconception that this is Perl’s sole function. Some people even believe that Perl was designed for use in CGI programming. This is clearly wrong as Perl was, in fact, written long before the design of the CGI protocol.

And then today, Justin Weiss posts the answer to the eternal question, “Can you learn Rails before learning Ruby?”

Or how about a more classic variation: Do I need to know Ruby in order to learn Ruby on Rails?

I fear Ruby is going down the Perl path already…

The Sad State of Too Many Perl Videos

I’ve been a good boy lately and have settled into a good exercise regimen. The combination of an exercise bike, and Apple TV, and a 46” inch television screen in the same room helps. I can watch half a tech talk while I pedal away.

It’s also once again driven home how tough it is to find a good Perl talk that you’d want to watch. I hate to say it, but too many of them are embarrassing — shoddy audio quality, bad video quality, a weird pattern of cutting to the slide and back to the speaker far too often. Look, I get it, Confreaks can’t be everywhere. (Just for kicks, a search for “Perl” on Confreaks returns one video – a Katrina Owen Rails refactoring exercise that has the dumb luck to have the word “Properly” in its title.)

A favorite recent Perl presentation featured the camera locked in on the projector screen because it was a live coding exercise. That works out well. I’d rather see the screen than the speaker, anyway. Problem is, anytime the speaker cleared the screen, the camera would lose focus. With no areas of differentiation to find near the middle of the screen, everything would go blurry and you could picture the auto-focus searching for contrast to hone in on. It was only when he got to the middle of the screen that things would snap back into focus. Here’s a sample.

I tried to watch another presentation that would have random jump cuts. We’d just lose 30 seconds or a minute of the presentation every so often. Here’s an example. Were they recording on a DSLR and needed to stop the recording every five minutes due to file size/manufacturer limitations?

Here’s a DBIx::Class presentation that begins with nearly two minutes of dead air. That’s thirty seconds of editing time someone missed.

I’m pretty sure the audio and video aren’t lined up in this YAPC DBIx::Class presentation. Since the speaker’s square is so small in the corner it’s not a big deal, but it is annoying. Also, the presentation is horribly laid out. The speaker has slides and seems to wing it from there. He tries to come up with examples off the top of his head but can’t. He skips over plenty of bullet points. Maybe that’s because the slide deck is meant for a longer presentation and he had to squeeze this in? I don’t know.

Perhaps the most awkward videos to watch were the ones at YAPC NA 2014 (here’s one sample and a much smaller second example) at a venue where a large mirror hung on the wall behind the speaker, reflecting a sea of bored looking faces in the audience. Makes you realize how tough a job any presenter has to do.

I didn’t have to search that hard for these issues. They’re pretty easy to find — just watch just about any of these videos. It’s frustrating in many of these examples, in particular, because they’re ones I’d have liked to watch without all the distractions or problems that made them completely unwatchable.

So, yes, I’m just whining tonight. Now excuse me while I go hit the bike and learn nothing from all of the above examples and try another one… Sawyer X is usually a good presenter. There’s a talk he gave on Asynchronous Programming I’m going to try tonight if the piss-poor audio quality doesn’t drive me completely batty.

Update: As it turns out, the audio wasn’t the issues on that Async talk. It was the video:

That screen is impossible to read code on. Thankfully, the slides are available on the web, but reading them on an iPhone is not a big improvement. ::sigh::