Is Elixir a good first language?

Few months ago I thought about this question and I was sure that the answer is: NO. Then, I realized that it was a bad judgement. I was worried that functional programming may scare and Elixir can be perceived as “complex”, but when I summed up all my knowledge about OOP and how different it was from simple math, where functions were introduced, I see that Elixir is propably the best first language.

There’s no need to overwhelm someone with classes, interfaces, methods, static and protected accessors. There are no constant and static fields nor global values. Elixir is the ultimate language - if you’ll love it , you ain’t gonna need to learn another one. And you just will not want to. It’s a perfect mix of beauty and effectiveness for newbies.

I think that elixir (or erlang or anything else that runs on the BEAM) is probably the best language for web apps and other backends, especially if you’re inexperienced, because preemptive scheduling limits the harm a slow function can do to your system. AFAIK, nothing else can give you this garantee. See, for example https://m.youtube.com/watch?v=5SbWapbXhKo.

If you can handle CSS you can certainly handle elixir. But don’t believe enyone who tells you that elixir is simple and has no magic. Elixir has an extremely inconsistent syntax, an you’ll take some time to read it fluently. It must be really hard to get into for someone who doesn’t know any programming language (I can’t be sure because it was not my first language, sorry :confused:). If you want simple look into erlang, a lisp (it could be LFE, which runs on the BEAM) or, for something outside the BEAM, python. If you can handle the rough parts at the beginning, elixir is a great language though :slight_smile:

Definitely. It is a scale. Some could say that managing your own memory is more explicit but few want to do that nowadays. So you do need a balance between expressiveness and explicitness.

2 Likes

From personal experience: resounding yes.

Some background: I’ve taught/mentored people with varying degrees of experience including many complete beginners.

Some reasons I think Elixir is in fact one of the best languages to start with:

  • Less jargon: Ruby and Python are widely used as first languages. However they come with heavy baggage. The moment you mention the word “Object” to a beginner is the moment you introduce a fairly big abstraction mountain they need to climb. Add to that “sending messages to objects” and they’re lost before even starting. In Elixir (or any functional language) you can keep it extremely simple: Functions + Data. Actions that transform data. You can go a long way and ultimately teach someone how to solve problems with code just with this idea. You can try and use this analogy with a language like Ruby but its awkward and at odds with most resources out there.

  • Pattern matching: This is incredibly powerful. For a beginner to be able to express things in a rather “visual” way is empowering. Consider the following example:

actress = %{
  first_name: "Octavia Spencer",
  born:  "25-05-1970",
  movies: ["Hidden Figures", "Bad Santa 2", "Car Dogs"]
}

Say we want to grab the latest movie (“Hidden Figures”). It’s hard to beat something like this in terms of expressiveness:

%{movies: [latest_movie | previous_movies]} = actress

You can explain the above result just by looking at the patterns. You could argue List.first etc can be used and explained effectively but then you need to talk about the List module etc whereas with patterns you have all you need in order to explain it already.

  • Tooling: Starting a new project, IEx, writing and running tests, helpful errors. All these were built with great care and with the end user in mind. They’re easy to use and remove many obstacles for a beginner. This is big.

  • Documentation: Easily one of the best ones out there for any language. Accessible both online and through IEx. Showing a beginner how to use the h helper in IEx opens a big door for them to explore things there and then.

All of the above combined make for a great experience, especially for a beginner. I’ve seen it in action and I’m actively still testing this theory. It’s worth noting that you don’t even need to cover processes or anything like that until much later on. You can go a very long way just with the above.

6 Likes

To me, OOP was very hard to understand as a newbie, especially the python variety which masks little syntactic distinction between class attributes and instance attributes and can use class attributes as mutable state. That’s why for a long time I mostly used functions and was afraid of classes.

Funcional/procedural progrmming (in which functions act on data, with or without mutable state) is much, much easy to understand. From that perspective elixir is way easier than OOP.

But how often do you have to deal with uncomfortable questions about syntax? And how soon do you explain things like , do: and the syntax sugar begind keyword lists to fake a variable argument list? Do beginners have a hard time understanding that?

Well, that’s a barrier that all languages have so that’s rarely the problem I find. I mean even in LISP you have to explain basic constructs and syntax regardless of the amount :slight_smile:

And how soon do you explain things like , do: and the syntax sugar begind keyword lists to fake a variable argument list?

You start going deeper here into details that most beginners don’t care about. Most just want to a) solve problems b) build the confidence that they can do it on a regular basis :slight_smile:

1 Like

Heh, big-time likewise, though I understand ‘how’ it does a lot of it now, just not really the ‘why’ in a lot of cases. ^.^;

But yes, Elixir is a fine first language, and get’s people thinking about synchronization early and in a good way, which is a wonderful skill in the modern world! However, I still think a typed language is better, like OCaml will catch a lot of programming issues at compile-time, tell you what is wrong, ‘why’ it is wrong, and in many cases offer a way to fix it, all before the code ever runs (and thus preventing it from crashing and burning and freaking the person out).

That is why I am not a fan of teaching things like Java and Python in schools as so many do now. The place I work teaches those too sure, but we also teach various ML’s (SML and OCaml) and students pick those up a LOT faster than java/python (while it also makes faster code, shorter code, and easier to read code IMHO).

So yes, Elixir is an awesome first language because it teaches concurrency early, but it is not a great first ‘language’ in terms of it catching beginners mistakes and helping them.

I’m still amazed at how well Rust does this! I recommend anyone that wants to learn a really-low-level-systems-language to learn Rust. Sure it ties your hands but it is for a very good reason! I actually quite like Rust, it is a bit verbose sadly, but not as bad as C++ in many area! :slight_smile:

My main issues with Elixir-The-Language over erlang is the syntax is not uniformly consistent, but the wonderfully built-in macro support makes it so I’m fine to deal with that. ^.^

latest_movie = actress.movies |> hd
# or sans piping:
latest_movie = hd(actress.movies)

Pattern matching is awesome yes, but don’t forget basic function calls either. :slight_smile:

Python is really more of a Prototype language (like javascript) than OOP, it just tries to hide a lot of its Prototypeness to keep things more comprehensible.

To this very day (an hour ago!) I still do things like:

def blah(a, b) -> a + b
# or
def blah(a, b) = a + b

>.<

Eyup there too. I actually kind of like the syntax but I highly think Elixir did not go ‘far enough’. Keyword lists are insufficient, I want full Erlang-style Property Lists! I.E I wish this syntax worked in Elixir (it goes ‘boom’ right now):

[:a_true_option, :something => 42, "anything to" => 6.28, more_options: 16, :another_true_option]

Elixir keyword lists only support this kind of @spec: list({atom(), any()})
Where Erlang Property lists support this kind of @spec: list({any(), any()} | any())
In the property list a simple [:blah] is interpreted as [blah: true]. See the proplist module in Erlang for more details.

And yes, I also wish that trailing keyword arguments in a function did not map to a single list of arguments at the end of a function, I really wish it required [/] around it, it confuses newbies who are like “Wtf, how are you passing more arguments then it takes?” and “Wtf, where is this magic list coming from?” and “Wtf, why can I not use this in other places in the function?” and more. That is part of some of the magic Elixir implicitness that goes away if [/] is required. And it is so ingrained in Elixir that it has to be taught early, which has contributed to at least one person that I know of not continuing to learn Elixir (among other things, though they were very biased against dynamically typed languages).

1 Like

I’ll do my best to help with this here :blush:

edit: title sugestions are very appreciated!

2 Likes

Yep, that confused me. I always use the list brackets so that my future self and anyone else knows it’s a list.

2 Likes