How does Elixir compare to C#?

I am relatively new to programming. I have been trying to understand programming for quite a while and think I have got the idea. The next step for me is to identify a good programming language that I can spend time studying deeply. Of course, I will learn new languages later on based on what I want to achieve. But what I’d like to know is: which language should I start with?

I have boiled down my choices to C# and Elixir. C# because I feel that it is an important language that is modern enough. Elixir because I am in love with what I have learned about the language so far. However, my evaluation of both languages is very subjective as I currently do not know any programming language deeply enough.

Is there someone here who knows C# through and through who could guide me and let me know how to make the right decision? Choosing the right language is important to me because I don’t have much time left for studying in my work routine.

If you know and love C#, would you still recommend I start with Elixir? If you know and love Elixir, would you still recommend that I go with C# as the first language I learn? Please share reasons why.

This will help a lot. Thank you!

I write C# professionally. I think every programmer should learn one functional language that doesn’t have same escape hatches like example F# does meaning they are immutable only. It will make you better programmer in the end even if you choose C#. I also think Elixir is easy to learn functional language. It’s also dynamic language and C# is static typed. If I where you I would learn both if you can starting from Elixir so you might gravitate towards better design in C#.

C# can be also be quite complex language with multiple ways to do same things. Also you have to think about things like thread safety and that means using locks etc. But C# might have better lot better job opportunities depending on where you live.

5 Likes

Thank you for your response! Unfortunately, I don’t yet understand what escape hatches mean, but I have a fair idea of what static typed & dynamic typed mean.

I know that C# is static typed. In fact, that’s what drew me to the language. I may be completely wrong here but I have this understanding that declaring variable types is good for memory optimization. Please do correct me if I’m wrong. What I don’t yet know are functional down sides to static typed languages (I understand they are more tedious to write than dynamic types languages, but are there downsides when it comes to execution as well?).

You have recommended that I learn Elixir before I start learning C#. May I know in a bit more detail why you say that? What exactly is better design?

I also don’t yet completely understand the differences between functional and object-oriented approaches. From the little I do know, I understand that the functional approach comes more naturally to me than OOP. What are some advantages the functional approach has over OOP, or vice versa?

You’ve already been of help to me, so I understand if you don’t have time to respond to all my questions. Thank you once again!

By escape hatches I mean that in languages like F# you can still do mutable things (change memory) if you decide to do so (escaping immutability), but example in Elixir you can’t, it’s immutable data only.

What I meant is that I think programmer should learn functional language and difference between dynamic and static typed languages. So if you learn both Elixir and C# you will get quite large spectrum of experience in different kinds of things.I think C# that lot of people write now days are less OOP than it use to be. If you learn functional language first it will mostly likely set your brain to this data oriented style. So when you learn C# you might tend to create more pure functions and use C#'s LINQ more etc. instead of jumping to deep class inheritance and things like that, that are bad.

Also functional doesn’t mean language can’t be statically typed, example F# is statically typed functional language. Static types usually also help with editor integration and that means things like better auto completion and refactoring tools. Also lot of things that are runtime errors in dynamic languages are compile time errors in static typed languages. Lot of people like static typing because these things and more. That’s why there have been languages for Erlang VM BEAM that just try to do that. But none yet widely adopted ones.

3 Likes

@wanton7 has brought up many good points here and in general I’m not going to disagree with what has been said. I quite like both these languages, I love elixir and for what it is C# I prefer compared to many of its popular competitors. These are probably a pretty good pair of languages to get a feel of very different parts of the spectrum over a good range of use cases.

I particularly agree that Elixir is a much simpler language and that the function style of it encourages simple solutions and a lot of good practices. C# particularly has a lot of extra stuff that is easy to get carried away with and OOP generally has a bit of a problem with people having a tendency to over engineer everything already. The main negative I can think of here though is there are much fewer learning materials for new programmers starting elixir so it depend on how those available work for you.

Another thing to consider is it can be much easier to learn when you are working on things that are useful or interesting to you. Elixir has a much more targeted range of use cases that it excels at and It focuses on those more or less excluding many types of software someone might want to make. Where C# has a much wider range of use cases it is intended for but it might not have some of the niceties when it comes to concurrency and things like that. So perhaps if you are more excited about building a desktop app or a mobile app or a game (perhaps with Unity or something) then C# might keep you interested thought the tough parts, but if you are more excited building web apps and services especially with real time features then Elixir might be a more interesting place to start.

4 Likes

Thank you so much for your explanation! This will be of much help!

Thank you! I understand that working on something you are excited about should be the best way to learn.

As it happens, I am more excited by the idea of building web apps with real-time features! I also believe that learning Elixir would be easier than learning C#.

Could you recommend how a beginner should approach learning the languages? Can you refer a course/book for Elixir? Could you refer a course/book for C# as well?

What are the thing one should consider before choosing a language? I know this is asking too much, but I would be delighted if you could share the same.

Thank you once again!

Different things work for different people a lot of the time, sometimes if you don’t feel like something makes sense you need to try a few approaches to learning it (look at the same parts in several books, check other courses, ask questions on forums like this). In general there are a few things that are going to make a huge difference learning a language irrespective of which language it is (and most would apply no matter the previous experience).

  1. Work through the learning material at the computer, don’t just read it or listen to it. By this I mean type out every example (don’t copy paste it from the downloadable version) and try to make it run, if you make a mistake try figure it out, when you get it working try changing it in various ways to see what happens, if it breaks try to work out why that might be, if your change works does it do what you expect? why or why not?

  2. Dedicate learning time regularly and consistently. Spending 10 hours one day working on it then coming back a week later and trying to pick up where you left off is extremely hard and it won’t have sunk in very effectively, you are much better to spend half an hour or an hour every day making gradual progress and quickly going over anything you need to revise.

  3. Use the documentation as you’re learning. When a book or course introduces something take a moment to look at the documentation that goes with it, in many cases you will see a bunch of additional useful functions that you may want to take a little bit of time to explore deeper but at the very least you will get a sense of what is there and where to look for it. Every once in a while you should try to use some of the things you find in the documentation so you are familiar with how it describes different kinds of features and are comfortable using the information you find to write some code.

  4. Try to solve problems you run into. This is a pretty tricky balance, you will learn so much more every time you figure out why something doesn’t work than when you get it right first time or when someone tells you / you look up the answer. However you don’t want to drive yourself to frustration, so try work it out, if you’re getting frustrated take a little break and give it another try, if you’re still struggling see if you can look it up or ask somewhere like here.

  5. Use the community. Particularly here there is a great community who are in general very helpful, there are also several bookclub threads discussing topics and issues people are having as they work through books. As well as that you can read a lot of threads where you can find out how people are solving different types of problems in real projects, you can see many projects people are working on and you can get insight from people working on the language and major libraries about how they are designed. So browse topics and ask questions.

For an absolute beginners introduction to Elixir that doesn’t assume experience with some other language, the only one I have heard of is Joy of Elixir (which you can read online here: https://joyofelixir.com/toc.html). I’m not sure if there are any others. With pretty minimal experience and a will to spend some additional time looking up some terms the Elixir & OTP course from pragmatic studio (https://pragmaticstudio.com/courses/elixir) is really really good, this course gradually builds out a web server with various features from scratch so you will learn a lot of things about Elixir and the ecosystem, how to build things up into an actual project, how web servers work and the essence of what a web framework like phoenix does. At a fairly similar point Programming Elixir (https://pragprog.com/titles/elixir16/programming-elixir-1-6/) is also a great book that again is a bit much to come into cold as a new programmer but doesn’t require large amounts of experience if you have some will to work through it. I found both of these to be very complementary to work through together and to cross reference. In both cases though you will find that they are intended for people coming from other languages so they will make reference or occasionally comparisons to concepts that many with an OOP background will find useful, so you might have to look up the term or just not worry too much and focus on the wider explanation. Another book that could be considered is Learn Functional Programming with Elixir (https://pragprog.com/titles/cdc-elixir/learn-functional-programming-with-elixir/), I’m inclined to think that it could be a slightly better choice of book but I have not read it.

After going through these you would be in a pretty solid position to work through pretty much any other material depending on which parts were more interesting, you could consider Elixir In Action for more OTP stuff, Programming Phoenix for getting into more web stuff or browse through the many other titles that might catch your interest.

Sorry not really, I learned C# mostly at work and read a couple of books to fill in the gaps but that was 7 years ago and since then I have mainly kept up to date through official docs, release notes and some language feature tutorials so I am extremely far removed from what material is good for learning the language right now and even more so when trying to apply that to a beginners perspective. Given the vast difference between the styles of language you would want a book that is not just describing the language itself but also teaching the concepts of imperative and object oriented programming (an absolute beginner book really, there are plenty I just don’t know which ones are best).

A few things that I often take into consideration:

  1. Is this language well suited for what I want to do?
  2. How does this fit into career / job opportunities? This could be that there are many jobs in that language, that there are jobs of particular interest in that language or perhaps that it will involve a different way of thinking that adds to the overall perspective. It could also be fine to just do it for hobby projects/interest, but that should be a conscious decision.
  3. What does this language bring to the collection of language I know? By this I mean will it allow me to do something I currently can’t (e.g. maybe learning Swift because it is the main language for iOS), perhaps maybe it offers some concepts not found in other languages that are really interesting to learn from, perhaps it is modelled completely differently (if I only know OOP then maybe learning a functional language) that means I learn to think in completely different ways and can take those lessons across languages.

In general though, I would suggest a new programmer does not try to learn many languages in the first year. Focus on one, learn it well, learn the concepts well, explore some of the libraries and frameworks, learn essential engineering practices like automated testing, how to deploy an app somewhere etc. Later learn a completely different language, again pretty well, think about the differences, think about what each is better for, think about the design decisions and how they are approaching the same fundamental problems each has to over come. After a few years and a good foundation in a couple of languages you can easily start to jump around learning parts of some things that interest you or learning something more in depth to reach a goal. If you jump between things at the start you will end up going nowhere. So I think the main thing with the first language is choosing one that you can stick with, usually that means one that is good for the projects you initially are interested in exploring.

8 Likes