Ilyes512

Ilyes512

Elixir VS C#

So hey guys. I was wondering how you guys think of Elixir VS C# (pro’s and con’s). I personally chose to learn Elixir and Phoenix for web based applications (inc. API’S) as that is my main focus.

So I have some college’s at work where we mainly use PHP with Laravel in the backend and javascript (Angular 2) in the front-end. We also have an application written in C#.

So to summaries my college’s standpoint: “C# can do everything that Elixir can do and more, while being backed by a large tech company with more job opppertunities on the current market.”.

I am still in the very early state of learning Elixir and so I cant come up with pro’s for Elixir. BTW he is also against functional programming languages in general (as in, funcional languages cannot replace oo languages). He also made a point that with OO you can do some functional style programming while it’s not possible to do OO style programming with Elixir.

So I wanted to share this and see what you guys think. I stick with Elixir because I like it (and it is different), I will probably take up C# eventually in the future.

First Post!

mkunikow

mkunikow

I don’t think so this is the same league to compare this two langauges :slight_smile:
Elixir is dynamic, strong pure functional language vs static typed OO C# (maybe with some functional aspects). C# is more close to Java for me. C# is not even close to Scala. In Scala league is F# from Microsoft Family.

Except this Elixir runs on Erlang OTP actor model The actor model in 10 minutes. You could get the same if you run your C# code in Akka.NET

But I think I agree that you can do more in C#. Elxir/Erlang is specialized to write robust distributed/web systems. It is good to know what tool use for task :slight_smile:

My 2 cents about OO mutable languages. It don’t like them at all. It is very hard to reason about flow when you mutate data. And is very hard to write concurrent system using for example threads when you need to secure access to common data. And even in OO they say “use composition over inheritance”

My conclusion:
You should know at least:

  • one OO language
  • one dynamic language
  • one functional language
    The best idea is to learn every year new language :slight_smile:

Except this one cloud platform Amazon WS/Microsoft Azure/Google Cloud Platform :wink:

About functional jobs, I think not so bad :slight_smile:

Most Liked

sasajuric

sasajuric

Author of Elixir In Action

IMO the most important reason for using Elixir is to take advantage of the underlying Erlang VM (BEAM). The VM gives simple tools with very strong guarantees that make it possible to build highly available systems. IMO HA is a crucial property for web servers, and many other kinds of systems that need to run continuously and perform many simultaneous tasks.

With Erlang, it’s easier to reduce an impact of individual failures (and thus keep providing most of the service with no interruption), as well as detect failures and react to them (thus making the system self heal). I’ve seen examples of both in my production systems, and I think it’s a huge win when a system is able to provide as much service as possible, and resume complete service as soon as possible.

I’m not aware of any other platform which gives guarantees as strong as Erlang. It’s certainly not CLR, nor is it JVM. Some languages and frameworks (e.g. Scala/Akka) might resemble Erlang, but they will not give same guarantees. There will always be some hidden gotcha, or an inferior implementation of an Erlang concept. It’s simply due to the fact that the underlying runtime (e.g. JVM) doesn’t provide the same guarantees. IMO, these days only languages which target BEAM (i.e. Erlang, Elixir, LFE) can get such strong guarantees.

I talked a bit about this in my interview for InfoQ, and also in the first chapter of my book (it’s free, so you don’t need to buy the book to read it :slight_smile:).

I’d say this is in fact a weakness of OO. And I should note I’ve been doing OO since around '95, professionally since '01 (including a lot of C#), while I’ve been working with Erlang since '10. So most of my background is OO and I’ve in fact been a happy practicant of OO, until discovering Erlang.

One problem is with mutable variables: it’s easier to introduce a bug due to unexpected mutation. Just a few weeks ago I spent a few hours debugging why something in my JS code doesn’t work as expected, only to discover that I was mutating a var where I shouldn’t have. That can’t happen if data is guaranteed to be immutable.

In OO you can never be sure about that. You can try to use only immutable vars, but in a large code base it’s hard to be certain it’s always true. Moreover, even if your code is immutable, your dependencies might not be, so there are no strong guarantees.

This might seem like a trivial thing, but it is quite important in a complex code base. Knowing that something can’t change when I call a function (since data mutation is not possible) is a big gain. It makes it easier to reason about the code and gives me bigger confidence.

Finally, FP is more explicit (so less magical) than OO. You call a function, pass some inputs, and get the result. In OO, you call a method, and it’s not clear what does it do to the state of the object. You need to read the implementation to understand what has been changed. In a dynamic language it becomes even worse, since when calling some_object.some_method(...) I can’t know what’s the type of some_object. That frequently makes the reading experience harder than it should be.

So while OO can simulate FP, it’s never completely there. After spending a couple of years with FP, my impression is that it’s at least as easy (if not much easier) to manage complex codebase, so I don’t see the need for OO features anymore.

14
Post #3
rvirding

rvirding

Creator of Erlang

One thing we found very early on is that no language is good at everything. Languages, and their systems, have a specific view of the world and whether this view fits in with the type of system you are building will determine if it is the right choice. OO and concurrency view the world differently. And saying that I can program anything in my favourite language so I don’t need another one is a completely useless argument. If we follow it to its logical conclusion we should do everything in assembler. The issue is not really what I can use but what is best to use.

Another thing we have found is that many (most?) large systems have different requirements in different parts of the system in which case one language will not be best for everything. So very many larger erlang based systems will have things written in other languages. This is relatively easy to do in erlang as it is easy to interface other languages/systems. Often you will find erlang is used as a “concurrent glue” to hold things together and interface between them.

What I say about erlang here of course applies equally well to elixir.

11
Post #9
nubunto

nubunto

OK, I really haven’t read any replies from the page but I’m going to give you some pros about Elixir.

About the “OO” part

Ask your colleague if he ever heard of Dr. Alan Kay. Kay was the computer scientist who coined the term “Object Oriented Programming”. He invented the paradigm.

The truth is, Elixir is object oriented. In the classical sense. I won’t get into it, but you can check out the rationale here (seriously, go read that article!).
Actually, is C# who can’t get it’s own object orientation **** together. That’s not C# nor Microsofts fault though.

About the “C# can do what Elixir does” part

Well, that’s not actually true. Ask him about compile time macros. Ask him if, with C#, you can do this:

defmodule MimeTypes do
  HTTPotion.start
  HTTPotion.Response[body: body] = HTTPotion.get "http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types"

  Enum.each String.split(body, %r/\n/), fn (line) ->
    unless line == "" or line =~ %r/^#/ do
      [ mimetype | _exts ] = String.split(line)

      def is_valid?(unquote(mimetype)), do: true
    end
  end

  def is_valid?(_mimetype), do: false
end

The whole article can be found here.
Seriously. Take a good look at that code, because it breathes awesomeness. That code is compile time code that goes into the SVN of freakin’ Apache, takes out all the valid mime types FROM THE SOURCE, IN COMPILE TIME, and creates functions for all of them.

I’ve never seen C# code like that.

About the part that Elixir is awesome???

No need to say anything about that. It is. Period.

About the part that Erlang is awesome

Do you know of a project written in C# by a team of 30 people who can do 2 million concurrent connections in a single server, also backed by a large tech company? Well, I do know one in Erlang: Whatsapp.
Which is the base for Elixir. I don’t think I need to say anything more.

About the part of “more job opportunities”

As people from the software area, we all know the game changes too fast. There may not be jobs now, but I’m sure there were a group of people that dismissed Rails back in 2004 saying there would be no jobs for Ruby. And here we are, aren’t we?
I missed the Rails bandwagon, but I won’t miss the Phoenix bandwagon.

Distributed programming is easy with Elixir

C# though? Hell no. In my company we kinda use C# for everything, and I must say that distributed C# is painful. With Elixir, though? Hell, give me 3 machines so I can boost my app up!

Anyways, is great to have different opinions. Elixir isn’t great for everything, and the same can be said about C#. Right tool for the job, always. I hope I could shed some light on some of the many good points of Elixir.

Last Post!

OvermindDL1

OvermindDL1

I was comparing what Generics could do compared to OCaml modules (I’m not touching C++ templates, if you think my above OCaml post was long, you’ve seen nothing! ;-)), I was not elaborating on everything else modules could do, just based on ‘just’ generics and what they could do, they are horribly inefficiently done. ^.^

A class is a type sure, but there is a whole set of classes can that fulfill a given type, but accessing those class instances require dynamic dispatch, that is one of the main failings of heavy OOP systems in performance constrained code (personal experience especially, plenty of docs on google about this like What's wrong? as an initial find, and I quote Virtuals don't cost much, but if you call them a lot it can add up. aka - death by a thousand papercuts when it is entirely unnecessary).

Lol, I really want an OCaml->Elixir backend written. ^.^

OCaml is in a fuzzy place for me. For ‘real work’ that will be hosting a long lived server that needs uptime, I’ll use Erlang/Elixir. For ‘real work’ that is more usual programs I use either C++ or (much more often recently) Rust. OCaml is more ‘fun’ for me, I enjoy programming in it, and it is certainly doable with real-work, I just never end up choosing it for real-work, but I only have very few good reasons (maybe only one) as to why I would not choose it (it still has a GC for example), where I have a LOT more reasons to not choose anything on the JVM or .NET systems for real-work (ew GC, ew OOP, etc…).

Rust I really have to espouse on again, it really is C++ done right, strongly typed, no GC, does not even need a GC as it uses proper semantics for handling all resources (not just memory), basically C++'s RAII baked in to the language with brilliant borrowing semantics. Still not as functional as I would like, and I do fight with it a lot more (mostly with its macros, I have borrowing down solid), where OCaml, if I fight with it, it always shows me how I was wrong in the end, and I come away more enlightened. ^.^

(Fighting with Rust on the other hand just leaves us both battered and me bugged at the lack of any form of higher types in it or anything like a C++ template system…)

Where Next?

Popular in Discussions Top

scouten
I’m looking for a host for the server part of a small (personal) side project that I’m working on. It’s currently written in Node.js and ...
New
AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New
slashdotdash
Phoenix Live View is now publicly available on GitHub. Here’s Chris McCord’s tweet announcing making it public.
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New