Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: Elixir as a First Language?
14 points by freedomben 33 days ago | hide | past | favorite | 16 comments
I was recently asked, "Is Elixir a good first language for someone to learn who has never done (serious) programming before?" After thinking for a minute, I realized that at some point in the last 20 - 25 years I really lost touch with this area.

My first language was C, and I did and still do think that was a fantastic first language because you can start very simply and don't have to learn a ton of programming concepts prior to writing some code. In my experience, learning to code is much more likely to succeed if you can write something (even hello world) and iterate on it. For example, working with people learning Java as their first language, they really struggle because you can't really do a hello world without encountering objects, classes, static keyword, public/private, and other things.

I love functional programming and Elixir, but I do worry that it has a few things like that to learn that might be a barrier to entry for a brand new programmer. Since I started procedurally and years later learned OOP, and then after that learned functional, I have so much baggage that I'm not sure I can weigh Elixir as a first language.

There's also the obvious, "what do you want to do with it?" question that matters. For example if you want to write frontend SPAs or mobile apps you have less flexibility. In this case however, that's largely irrelevant.

Is there anyone here who learned Elixir as their first (or first serious) language who can comment on this? Or is there anybody who started with a functional language and/or a lisp or similar who can comment?

Excellent question! In choosing a first programming language, I think the most important things are (1) acquire generic knowledge, (2) have help along the way.

(1) The most important thing to keep in mind while learning a first programming language is that it should teach you the abstract notions of programming, without entrenching your mind into a particular programming paradigm. (When I say paradigm, I mean procedural, functional, object-oriented, message passing---I'm sure I'm forgetting a lot.)

I have seen countless _very good_ software engineers struggle when switching but from one paradigm to another, but not between languages of similar paradigms.

In that respect, a multi-paradigm language is the ideal first programming language. Elixir's origins are functional, but it's evolved to be a multi-paradigm language [1].

(2) To have help along the way, you either need a strong/active community, OR a very helpful compiler. Elixir's compiler isn't particularly helpful, and the community is nascent, so in that regard Elixir isn't the best first programming language.

At the end of the day, I think someone's pre-existing mental model of computers should be the tie-breaker (for example, if it's someone with a strong mathematical background, I think they'd enjoy Elixir more than someone who'd get a kick out of making a cute website-based game.)

[1] I'm guessing the Elixir community would consider purely-functional Elixir as the most-aesthetically pleasing Elixir, keeping true to its Erlangian origins.

I have to take some issue with your community appraisal. The Elixir community is certainly smaller than some but they do exist, the community is pretty active, and are very welcoming of newcomers with beginner level questions usually answered with good timeliness. My sense is that this has been improving over time. As a beginner with Elixir, this has been my experience.

Anyway, my take is that the strength of the community is perhaps greater than you've given credit for.

^^ likely a more accurate opinion than mine -- I've been a recluse for ~18mo

Yeah, why not? My first language was JS but i use Elixir daily and it definitely made me a stronger dev. What hooked me into Elixir was seeing it for the first time and getting really excited by being able to read the code line by line without knowing the syntax and getting a good sense of what was happening.

But three things i think that really matters for someone to pick their first language are: 1. Is syntax and data types easy to grok right off the bat? 2. How fast are they able to make a mental map of the flow and transformations of data only by reading the code? 3. Are the docs easy to read and navigate, and do they instill understanding?

Elixir definitely is for someone that wants to learn it, and are okay with the fact there might not be many resources to learn from. But what i gathered so far is most of the resources and the community really seek to help someone get a deeper understanding of the language and think about the things that go beyond languages like system design and code quality. Yeah there isn't many packages and libraries out there like the more popular languages to put stuff together, but that's where the fun begins. It's like being in uncharted territory where one is forced to engage with what they're doing and learn how to really build stuff from scratch.

For someone thinking about elixir as a first language, hacking around a basic module and testing it out in the repl to building a web app with Phoenix is a great way to learn.

My unpopular opinion: start as low-level as possibly, preferably with assembly. A hello world in assembly is ~7-8 instructions on x86_64, provides easy introduction to debuggers, OS internals, and architecture, and will help understanding higher level abstractions.

Starting with high-level is fine if they just want to get a job (in which case they should probably just go straight to JS, Java, or C++), but if they want to really learn and understand, start with low-level.

I can't say you made a great point by saying java is worse than c. Seems trivially identical to me.

    #include <stdio.h>
    int main() {
        printf("Hello, World!");
        return 0;

    class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello, World!"); 

what is stdio, printf? whats f? return 0? The important thing is that actually all those questions are irrelevant. programming is complex, it can't be simplified, the steepness of the on ramp is irrelevant. if you want to climb the mountain you will. the climbing is the value the grade of the hill is irrelevant its a constant factor. People dont stop programming because java is verbose. They never really get past tutorial hell and build something they care about.

learning to programming isn't made easy by a language. learning calculus isn't going to be easy if you choose infinitesimals vs episilon-delta. Building understanding in your mind is the process of seeing the important structure through the fog of syntax.

If all you're doing is copy/pasting and accepting tons of magic, sure they're not much different (although you left out an important (and very common) stumbling block for Java: the filename for your example must be HelloWorld.java, and there are other conventions like that that you have to know).

But what's step 2? You start learning what each line does. With C it's "this #include basically copies in some other file, and printf is a function, and functions do this ...." To understand those lines in Java you have to learn lots of OOP terms (class, object, public, private, static, etc) that are layered on top of programming. Just learning what a "function" is is kind of hard at first. By having to learn methods instead is more friction. Now that most schools teach python or javascript first the debate about "early objects" is a lot less intense because most languages don't force OOP onto you with as heavy a hand as Java.

I also very much disagree that the language doesn't make it easier. I would agree that the concepts are the same, but the bridge between abstract and concrete is the programming language you learn, and some will be more natural (aka easy) for some people.

well you just repeated the same argument I didn't find convincing. i already said syntax is irrelevant and you are just asserting with no basis that C syntax is so much easier to comprehend that java will cause newcomers to stumble. absurd.

Let me start by saying that I really like Elixir as a language and ecosystem. That said, I don’t think it’s a good choice for a first language.

Elixir excels for building highly available networked backend applications. Not that it can’t be good for other things, but I personally tried my hand at it as a scripting language (as a complete newcomer to programming might). For this purpose I had to learn things like Erlang interop, module composition, setting up a mix project, etc. — just to get a small project off the ground. Even as a seasoned developer familiar with syntactically and conceptually comparable languages (Ruby, OCaml…) I found the self-instructional overhead to be atypically high for a programming environment.

This is a bit of a tangent, but I’ve noticed that whenever “best first language” discussions come up, responses tend to be biased toward whichever language people first scrapped something together in for fun. For me that was TI-BASIC. By no means do I think that was a “good” first language - it’s just what was around. But it passed the litmus test of letting me quickly iterate from writing calculator-crashing output loops to making little games for my friends.

For its virtues, Elixir was originally developed to serve a community of experienced web devs trying to solve problems most newcomers don’t know about and won’t encounter — and it shows. I think most novices would be better served by a more “mainstream” scripting language like Python, Ruby, JS, etc.

No. There could be two ways to teach programming - one by doing - e.g building stuff. In that case all the popular web dev languages are good (javascript/python/ruby) because they are comfortable and it is relatively easy to build an app. Try doing that in C for instance. The other way of teaching is less by building a functional app and more by deep diving into computer science concepts like how arrays are implemented, what are pointers etc. C is usually used for that and I'm not a big fan of this style of teaching though many universities do it.

As for Elixir - going functional with your first language will just be confusing - the student will probably have to learn JS and other OOP languages soon. It makes more sense to me to do this transition when you are an established programmer.

And finally Elixir is not considered an easy language. Your first language ideally will let you get things done in the easiest way possible. For me that also puts typed languages as not ideal but I'm a minority there.

When you've never ever written code everything is hard - I see no point in making it harder so no I see no point in choosing Elixir as a first language.

Finally there's the job market of course, that small thing. Elixir in general is more suited for senior devs who are called to work on super scaley problems and the amount of jobs is small, that's not ideal for a beginner. However I will concede there are way fewer people who know it so maybe it could work out when applying to jobs.

It really depends on the purpose of learning the language. If it's the first one, I would assume a general lack of broader perspective. As I remember how clueless I was - PHP, Ruby, Python, etc. didn't mean too much to me except having some cool logos and different syntax, from which, well, it was also hard to tell anything because I didn't know all these building blocks.

If the main purpose is to find a job, then I would check if there are local Elixir communities/companies nearby that could guide along the way. Elixir is a niche compared to other options out there, so I would recommend doing this ONLY knowing that there would be a strong support available on the way, from start to finish (landing an entry-level job).

On the other hand, if the main driver is curiosity to get into programming and that person feels drawn towards Elixir the most, I would say "just do it". The sheer will to tinker and build cool stuff that works can inflict a very positive feedback loop, which IMO is one of the strongest drivers to bettering oneself at coding. Even if that attempt turns out to be a failure, it's better to fail fast and give something else a try. I believe that in such case, the time spent on tinkering with Elixir will pay off anyway!

I started out with Common Lisp and David S. Touretzky's book[1]. The great thing with Lisp or Scheme as a first language is that it requires learning very few concepts and very little little syntax to get started. Lisp isn't terribly functional, but the functional style feels natural to use.

I like the idea of starting with pure functional programming. With procedural programming you have to teach two concepts, functions and side-effects. With pure functional you only have to teach one of those concepts. That is until you need to interact with the world, ideally you'd start out with a framework that papers over all of this. Maybe Elm would be good option for this reason? It helps that you can easily produce something graphical that can be interacted with from the very beginning, and building web apps is probably the most common application for programming these days.

1. https://www.cs.cmu.edu/~dst/LispBook/book.pdf

Erlang/Elixir is best suited for large, long running, distributed system.

Why? Because it has all the tools to handle such complexity, but you still need to understand it.

Someone who has never developed anything serious, or does not know programming, surely don't want to start with implementing such a system because they would not know what is the complexity, what is required, what are the footguns, etc...

By following the principle "use the right tool for the job", elixir is not the right tool to write "hello world".

My subjective answer to your question is: no it's not a good first programming language.

My bonus point: But down the line, you can only benefit from learning it.

> Why? Because it has all the tools to handle such complexity, but you still need to understand it.

Eventually yes, if one wants to participate in open source or work professionally or write a very non-trivial application, but why would you need to understand OTP and actors and such when you're first learning? A hello world can literally just be a single line:

    IO.puts("Hello World")
and you execute it with: `elixir hello_world.exs`

When you get to parallelizable stuff, I think every language will have a learning curve. I do tend to think that OTP/erlang stuff would be harder, but thinking further on it I'm not sure why it would be harder than say threads or runnables in java or ruby, or asynchronous stuff (promises and callbacks) in javascript. Definitely interesting to think about.

The Elixir stuff that I was thinking of that might be harder are things like immutability, pattern matching, anonymous (aka lambda) functions, etc. To some extent though even those can be avoided if you're writing simple personal scripts or solving Project Euler problems.

Definitely worth some thought though, thanks

> A hello world can literally just be a single line

Yes a bazooka can kill an ant. Does it make it suited for the job?

> things like immutability, pattern matching, anonymous (aka lambda) functions, etc

Immutability is easier to understand than all the problems that arise with mutability. Also with Elixir, unlike Erlang, you can rebind a variable, which does not break mutability and yet gives you some liberty with what you're doing.

Pattern matching might be the most natural thing in the world:

| I have this on the left, does it look like this on the right?


| Bunch of if/else/switch/... that basically answer the same question

Since I tasted pattern matching in Erlang/Elixir, I just feel limited whenever I go back to another language.

But while those features might be nice and all, once you start searching about Elixir, the literature/forums/chats will be all about OTP, best practices, gen servers, distributed systems, and all of that. Because that's what 99% of the people using Elixir are doing.

Just like starting with TypeScript, one might expect to see a lot of Javascript thrown in the mix.

This will only confuse the newbie because they will not know what they're are reading.

i haven't even learned anything yet but a microscopic amount of java and lua but i might try elixir

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact