Elixir vs Python

This is like comparing a hammer to a wrench and saying that the wrench is superior.
Sure you can swing a wrench like a hammer but it does not mean you should.

All in all just pick the thing that matches the issues you are trying to solve.

If by saying one is superior to the other then I’d ask in what context.

I’d say python is superior in computation due to their more preferment math lib.
I’d also say that elixir is more superior in distributed systems and fault tolerance.

That said neither issues I’ve listed are exclusive to either Python or Elixir let alone any other lang.

3 Likes

I stumbled on a surprising instance of Elixir being much easier to learn and use than Python: I was in each one’s REPL, comparing how to do some typical programming task. (I forget exactly, but it might have been JSON parsing.)

The function in each language was easy to call. And in Elixir, the REPL printed out the data structure result, and I could see exactly how it parsed the string.

Python, however, is object-oriented. And so it gave me a single result object. But the author of that class hadn’t written a __str__ method. And so the REPL couldn’t show me the data, and only produced the unhelpful default representation like <JSONResult #12682362>. In order to actually see the result, I’d need to consult the documentation/API and learn what methods I needed to use to extract the info. And then use them precisely as intended, and hope they work as documented. (Sometimes they don’t.)

But at that point, this was an epiphany. I stopped playing with Python and continued using Elixir. In Elixir, your data is simply right there.

6 Likes

I will say I hate Python for the single reason that it will blow up with a mix tabs and spaces. I can’t tell you how many times I was working on a file that someone had added a tab in only for it blow up on me with a horrible error that had nothing or little to do with the issue of the whitespace.

3 Likes

brutal. I just lost a battle at work and won’t be able to update our bff/frontend to elixir from python (our backend is elixir, feels backward somehow). Wish they could understand this, because I have felt this pain so much.

I was thinking, you can hide your data in Elixir inside of a genserver, but then I remembered you can still see the tail-call state of that genserver with sneakiness =D. I think the only true way to hide yo’ data is to use a resource.

Well, that is hardly a reason; not implementing Inspect for your own struct in Elixir might result in rather unreadable outcome. Yes, thanks to core team, it’ll be somewhat printed, but the result is also not guaranteed to be comprehensible for deeply nested structs with very long keys.

You also have Erlang’s sys module, so with a pid you can do :sys.get_state(pid) and get the actual state, and there’s other functions in sys. You can also always create a specific handler to handle the state inspection (though both sys and handlers require that the server isn’t blocked doing something).

I have no horse in the race between elixir/erlang and other languages and sometimes I wonder looking at the code why I prefer to work with elixir/erlang - but in the end it boils down to the actual simplicity - once you have in mind the very basic building blocks everything more or less follows the same structure (supervisor, children (which usually have more children), monitor/link, trap exits or listen for down messages, start->do stuff in steps->stop) and extending a gen_server, or gen_statem to handle new cases, new flows and/or new paths is usually pretty trivial in my experience - the same with adding concurrency to it, limiting the concurrency, etc. Lastly usually if you’ve isolated the servers, changing them to a new independent app is a matter of moving the modules and changing a few lines in the supervision trees. To me it just makes sense. Of course, some things are expensive to do in the beam but since I usually don’t need super fast arrays or anything like that where mutability shines, I’m ok with that.

2 Likes

Alright since we’re beating a dead snake here, I absolutely hate how when you install a library it’s unclear where it goes and if you have two packages that require different versions (I’m looking at you, tensorflow) the solution is to create an virtual environment that changes your whole system setup with hidden variables to manage it. Don’t ask what happens when your environment registry gets corrupted (historically at that point I have reinstalled Linux as a solution, but I’m not exactly the smartest)

3 Likes

I often use python as a helper of my phoenix project.
For instance, I wrote a test script for tcp server which is written in elixir.
It is important to think of “when to use python, when to use elixir”, I think :slight_smile: :smiley:

1 Like

As a long-time Python programmer, I cannot agree more :grin:

Hi all , In other to works with api like facebook business API for example to interact with their messaging system , which choice could be better between Elixir and Python ? Advantages or Disadvantages ? Your answers will be the most welcome