Is Elixir a good first language?

After html & css is Elixir recommended as a good first programming language for web apps and backeds of mobile apps?

If you go with Phoenix Framework 1.3, I think it is very clean, expressive, and relatively simple with good documentation and lots of tutorials on the 'net. Most importantly, I think it teaches very few bad habits. It’s approach to functional programming for the web is also easy to grok, and doesn’t require learning much if anything about OOP or similarly more complex topics.

That said, there are some less scrutable bits: ecto is not entirely straight-forward if you step outside of the simple use cases, for instance.

All considered, I’d definitely recommend giving it a go, but definitely go with one of the online video tutorials for Phoenix beginners. They are quite fantastic and can save lots of head-scratching moments.

1 Like

If we try to focus on Elixir as a first programming language, as in, your gateway to programming, I have mixed feelings about this.

Elixir has enabled me to build systems I have never dreamt of being able to put together before; that happened without sacrificing productivity, flexibility, and performance. How? It’s simple. The actor model is a hell lot more natural when building certain web services than using all the baggage that comes with other languages. Elixir is process-oriented, hence you kick things off with the Actor model from the start.

With that said, I wasn’t able to build my whole infrastructure with just Elixir. I have integrations with Python, Node, and C, simply because I need more tools that haven’t been ported to Elixir yet.

With all that being said, if I were to wipe my programming experience, and start from scratch right now, and I need to write simple backend services for mobile apps, I’d probably choose Node.js. That’s because I’ve developed about 3 services in Node so far, which haven’t taken more than a day or two, and I am still a complete beginner in Node. It just works. My second choice right after would probably be Elixir, tho.

If you’re trying to build a complicated backend, tho, with many realtime features, data crunching, cron jobs, … etc, Elixir has to be my #1 recommendation.

2 Likes

This book might be a good place to start:

Also see these threads:

2 Likes

Compared to some other widely-used languages (Ruby, JS), I think Elixir has way less opportunities to bread bad habits. I think that that - and not perceived complexity of the language - should be a primary factor in deciding whether a language is fit to be a first language. However, given that you’ll end up with having to learn only one language, when beginners want to learn especially about web stuff JS could be a candidate (even though I think it’s not a very good language despite it’s popularity - IMNSHO, the '90s were plagued by VisualBasic, the '00s by PHP, and the '10s by JS; I wonder what crappy language the '20s will produce ;-)). Similarly, when beginners want to learn about, say, number crunching etcetera, I’d advice Python.

I guess it also depends what they want to learn: some quick shortcuts towards producing stuff (see the aforementioned advice) or do they seriously want to become a craftsperson? In the latter case, I’d send them on a mission through pure OO (Smalltalk), pure functional (Scheme - study SICP), maybe some logic programming (Prolog), then through seven languages in seven weeks. Some people only need to learn to hold an allen key and a screwdriver so they can assemble Ikea furniture; others want to become cabinet makers.

1 Like

One thing we realized very early when developing Erlang is that no language is good at everything. Yes, you can do everything in one language but not well. This means that in most systems different parts will best be written in different languages. While this may not appeal to everyone it is the best way to build a good system. While Erlang/Elixir is very good for things like concurrency, fault-tolerance, scalability, parallelism, etc it is not good for things like raw numerical calculations. So use libraries written in other languages when they exist and do well what they should, we are very good at interfacing other languages/systems. So the most important thing is not whether things are written in Erlang/Elixir but whether there exists a good interface.

10 Likes

And the BEAM has multiple fantastic interfaces that I’ve been using for over a decade, so much easier to bind with than most other things, even native modules!

If you can get to ElixirConf this year, I recommend listening to Alexis talk:

https://elixirconf.com/speakers/#alexis_huefner

2 Likes

Urgh! No, no, no, no, no!

(alright, I might be overreacting, but still…)

  • Callback-based async makes it too easy to write spaghetti, and it’s syntactically nasty even in simple cases.
  • JavaScript is way too dangerous without a linter. For example, while Elixir’s == converts between floats and ints and that’s it, JavaScript’s is just broken.
1 Like

To note on @notriddle’s ‘callback-based async’-point: What colour is your function? is a great read.


I think Elixir would be a great language to learn as a first language. Of course, I am biased as I have been programming for a very long time, so what I think might have been good for me to learn first might differ from what actually would’ve been best for me.

The reasons I say so:

  • When starting out with programming, the first things I wrote were simple scripts that automated some tasks. (solving the ABC-formula, making a pocket calculator, building ASCII game of snake). Elixir is great at building CLI-tasks.
  • Its documentation, getting-started guides and books are top-notch and (as far as I know) do not learn you a bunch of idioms you might need to unlearn later.
  • Elixir’s ‘Explicit over Implicit’ credo results in code that is very readable, and having h SomeModule.some_function at your fingertips makes it easy to quickly learn about things you have not seen before.
  • There simply isn’t that much to Functional Programming. This is an advantage when going to Functional Programming as someone who is new to programming, but takes quite some getting used to when coming from imperative or object-oriented programming because of the difference in thinking about problems.

@rvirding I would say that raw number-calculation speed probably does not really matter to a beginner. Learning something like Rust or Haskell to do number crunching once speed becomes a concern later on is definitely a lot easier if you already have one functional language under your belt.
(Of course, your more general argument, that no language is good at everything, is still very important to be given note).

2 Likes

The biggest challenge for Elixir as a first language is that we have almost no resource aimed at developers learning to program. Almost all resources assume previous programming experience, with a possible exception being Introducing Elixir and the accompanying Etudes Book. So I would say you would need a mentor or someone to guide you as you learn.

On the positive side, we are getting more and more resources and it is only a matter of time until someone tackles Elixir from this perspective. crosses fingers

15 Likes

My reply was mainly a comment to that @Mazyod had to use other languages as tools were not yet written in Elixir. And I perfectly agree that a functional language is a good way to start programming. It should be a simple language, or at least one which has a simple subset which you can start out with and write “real stuff” before you get into the deep and complex. Also the very basic concurrency model is a good start when building systems.

I can’t stop myself here (I did try) but I find this comment amusing. :grinning: Coming from Erlang (and LFE) where everything is explicit I find Elixir full of implicit. :grinning:

4 Likes

This is an apples and oranges comparison. The JavaScript equivalent is ===. I do agree that it’s pretty much absurd that they don’t do it the way practically every other language does though.

agreed. theres not a lot of people who kicked and screamed more than I did using javascript. I didn’t even want to use it on the front end (but of course had to) now with the resources available its hard not to use it for quick proof of concept projects. Do I and will I go back and rewrite in something else than node? yeah and probably for some but in some cases probably not.

I can’t stop myself here (I did try) but I find this comment amusing.
:grinning: Coming from Erlang (and LFE) where everything is explicit I find
Elixir full of implicit. :grinning:

Yes, I find that too :slight_smile: Luckily it is functional and immutable so you
don’t dig yourself too deep down the hole

1 Like

I completely agree with @josevalim. I started learning programming 18 months ago. I began with intros to HTML, CSS, and Javascript. Then I learned Ruby and Rails. I actually wrote a blog post describing my first year. I spent 6 months learning the fundamentals of programming and web development with Ruby and Rails related resources and then switched to Elixir.

When you’re learning your first language, you’re also learning about the command line, Git, Github, deployments, and tons of other things related to programming outside of the language. The challenge with Elixir is you will have to track down resources outside of the Elixir tutorials and most often the resource is not going to be written in Elixir.

If you have a mentor to guide you then it might work, but if you’re more on your own, I would recommend Ruby or Javascript. Maybe Learn Functional Programming with Elixir will feel this need, but currently there is nothing in Elixir like Learn Rails by Daniel Kehoe or The Ruby on Rails Tutorial by Michael Hartl that walk you through the basics of web development.

Once you have a foundation then you can pick up Elixir. You’re not locked into the first language you choose (like I said, I switched to primarily Elixir after 6 months). Just my two cents as someone who was in your position 18 months ago.

Apparently way back in 2007 there was a bit of an experiment with Erlang as a first language:

Quote:

“After three days programming with Kara, we introduce Erlang’s
features for concurrent and distributed programming to the pupils,
which usually results in an ‘Oh, what a pity!’, when telling them
that we do not program with Kara anymore.”

Then, the students go on to implement a chat system.
Recall that these are high-school students with no
previous programming experience.

Learning Programming with Erlang or Learning Erlang with the Ladybirds (slides - pdf)

Seems these days only versions for transitioning to Java, Python, JavaScript and Ruby exist.


[erlang-questions] Ways to get started
Hacker News Discussion

1 Like

Exactly @axelclark, personally starting just over one year ago on my own from almost no recent background I went through Michael Hartl’s Rails Tutorial which I agree gives a great foundation in web development for beginners including basic treatment of bash, git/github, html/css+bootstrap/js, sql/postgresql, ruby/rails, etc. He has also released a series of good “learn enough to be dangerous” guides since then easing beginners into all of those ancillary topics as “prerequisites” for beginners before the main tutorial. I can’t recommend his learning material enough if you are just getting started.

After doing this, something about all the inexplicable Rails magic, implicit behavior, and domination of rails in apps just didn’t sit well with me… so I found myself reading many articles from the “ruby-off-rails” community written by brilliant rebels like Piotr Solnica, Jeremy Evans w/Sequel, and w/Roda, and Janko Marohnić` (among others).

I found Elixir through tweets and blog comments from like-minded rebels then went through the guides of Elixir then Phoenix then Programming Elixir followed by Programming Phoenix. Finally I went through the Hartl tutorial again, re-developing it all with Elixir/Phoenix instead. Although as a beginner you are spending a little extra time learning some Ruby before getting into Elixir I didn’t feel like any of this was a waste. You don’t spend too much time dealing with OOP patterns and Rails magic to be unlearned and I found everything learned was VERY easily applied to Elixir/Phoenix due to the similar syntax of the language, iex vs irb, mix vs bundler+rake, routing framework/helpers, exunit vs minitest, eex vs erb, etc. With this foundation, Elixir and Phoenix is actually much easier to understand actually since you can much more easily introspect the inner workings of the framework. The explicit behavior of the conn/request-to-response/plug pipelines and much more explicit behavior of ecto vs ar is very easy to understand.

I really think this is an excellent learning path for beginners making Elixir an (almost) first language despite having little real beginner literature available at this point. After feeling comfortable with all of this I believe the next steps are to focus on the more advanced parts of Elixir and OTP w/channels, concurrency, and the like. This progression worked very well for me and I hope it helps others!

1 Like

I tried to tackle that last year, never got time to invest into it properly.

It is honestly quite herculean because you have to introduce soooo many stuff before being able to really begin to dive into programming. Particularly the CLI and editor, how to install stuff, etc. That takes a big upfront cost, that i was not ready to tackle. Especially if you need it for the 3 different main OS.

But i may be interested in coming back to it later this year. We will see.

Heehee, you got me there! :stuck_out_tongue_winking_eye: Yes, Erlang itself has even less syntactic sugar than Elixir. Not being able to rebind variables might also arguably help somewhat. Also, the Prolog-like syntax won’t be a hurdle at all if Erlang is your first language. :slight_smile:

In all honesty, I personally do find that the Elixir pipes (even though they work on the first argument rather than last) help to improve the readability because it allows for a natural transformation flow.
What made Elixir at least for me easier to learn, is that the Elixir documentation is right now better connected and searchable than the Erlang documentation (Such as being able to read it from within IEx, searching for a module or function on hexdocs, going to the source code of something with one click from hexdocs, nearly all functions contain clear usage examples that are guaranteed to be up-to-date as they are doctests). I do like the new design that was introduced for Erlang’s documentation in OTP20, though! :smiley:

Still, definitely, Erlang is more explicit than Elixir. :sweat_smile: The point I was trying to make was more ‘BEAM vs. the rest’ (‘rest’ being defined as ‘OOP or functional languages that see common usage.’).

1 Like