4 ms·
People have argued that Elixir could replace Python, but tbh, Elixir’s syntax is too ugly to replace something as elegant and simple as Python.
by behnamoh 3y ago
People have argued that Elixir could replace Python, but tbh, Elixir’s syntax is too ugly to replace something as elegant and simple as Python.
- giraffe_lady 3y ago"i'm not falling for that hot take. that's clearly someone with a fetish for getting yelled at. i refuse to participate in that kind of perversion"
- Xeamek 3y agoSimple? Sure. Elegant though...
- deleted 3y ago[deleted]
- matsemann 3y agoI'll bite: Impossible to write pure functional style code in python, hence it loses any elegance contest right out of the gate. ;) I work in a python shop now, and the code I've written the last years must be the ugliest of my career. If it's too complicated to be solved with a list comprehension, it will be so much uglier than lambdas in a language with a form of piping.
- boxed 3y ago> Impossible to write pure functional style code in python What does that even mean?
- behnamoh 3y agoThey probably mean you need to import some modules to do things like partial functions. But it's not like functional programming is not possible in Python. I'd argue that Elixir's syntax is more of hindrance to FP than Haskell's elegant syntax.
- matsemann 3y agoNo, if importing something was enough it would be fine. It's more that how a lambda can only contain a single expression means you need to split and name things everywhere, how you can't pipe/chain things means you need to have intermediate variables or an ungodly amount of nesting etc. Yeah, technically feasible, but it's not "pythonic" so you solve it some other (to me) less elegant way.
- bPspGiJT8Y 3y ago> It's more that how a lambda can only contain a single expression That's exactly how lambdas (and all functions) work in actually functional languages like Haskell. And it's a good thing,lambdas shouldn't allow statements. > how you can't pipe/chain things Ironically after switching from Elixir to a language where I can have any operator I wish, I found myself using the equivalent of Elixir's |> only on a very rare occasion. IMO they're vastly overrated.
- matsemann 3y agoHmm, you can surely use multiple lets in a lambda in haskell, as in every other function? And it doesn't have to be the pipe operator, just something similar. Like list.map().filter().reduce() instead of reduce(filter(map(list))) which quickly gets unwindly.
- boxed 3y ago> need to split and name things everywhere It can sometimes be annoying yes, but when you come back to the code 6 months later it's mostly a good thing.
- matsemann 3y agoBut in other languages it's clear what the code is doing. If you have a chain of map, filters and other operations, they are all named and easy to grok. In a python list comprehension a lot of things will be going on, without named parts. So then you need to name stuff to keep track. So you got foo, then foo_filtered, then foo_sorted, then foo_grouped. And that doesn't really convey anything more than in a language where you would do foo.filter().sort().group().
- regulation_d 3y agoWhen I first started writing Elixir, I had no idea how much I would come to love immutable data as a language feature. "functional" can mean so many things, but for me immutable data as part of the runtime (i.e. not bolted on later) is one of the most important things. Never having to ask: did I pass by reference or value? Never having worry about data changing out from underneath you. It's pretty amazing. Sure there are times that a need for performance calls for mutable data. But for me those times are pretty rare, and when they happen it's usually easy enough to quarantine the mutation.
- nvarsj 3y agoI prefer Erlang to Elixir but I think I'm in the minority. Rubified Erlang has its place I suppose.
- sph 3y agoI mean, have you looked at Python's syntax for closures? You call that elegant? Any high-level language that is afraid of map/reduce and other functional constructs is a waste of time to me. Python has a lot of mindshare because it looks simple, but by God if it isn't an absolute kitchen sink of a language full of weirdnesses and gotchas. And still, completely afraid of functional constructs. Nice bait though.
- boxed 3y ago> I mean, have you looked at Python's syntax for closures? You call that elegant? You mean anonymous functions surely? The syntax for closures is basically nothing, you just make a function.
- bPspGiJT8Y 3y ago> Any high-level language that is afraid of map/reduce and other functional constructs is a waste of time to me Elixir is afraid of most "functional concepts".
- boxed 3y agoImo that's not Pythons great strength, although I like the syntax. Python is great because of the C interop. FFI in Java is horrible, and I assume it's not great in Erlang/Elixir either. In Python? It's pretty damn great. Which is why Pythons library ecosystem is so enormous.
- freedomben 3y agoElixir C interop is actually pretty pleasant. After Java I was expecting it to be a nightmare, but it was shockingly easy and well though out. The big thing in Elixir community right now is to write the native/performance code in Rust[1] and interop with Elixir. [1]: https://github.com/rusterlium/rustler https://github.com/rusterlium/rustler
- paradox460 3y agoThere are equivalent libraries for zig and Nim too
- josevalim 3y agoErlang has a well defined and clear layer for integrating with C code, including functionality to help you ensure the code you plug into will be thread-safe and work with the VM's underlying concurrency models: https://www.erlang.org/doc/man/erl_nif.html https://www.erlang.org/doc/man/erl_nif.html Erlang does not have low-ceremony ways of calling C from Erlang, as I believe Python has. It could be done but that would be frowned upon anyway, because it would defeat the preemptive and fault-tolerant guarantees of the runtime. So I guess it depends on what you mean by great. FWIW, Elixir has no problems integrating native code from XLA, LibTorch, Polars, that also powers equivalent libraries in Python.
- innocentoldguy 3y agoI'd have to disagree. Having used Python professionally since the mid 90s and Elixir since 2015, I think Elixir's syntax is cleaner and easier to read. I also think language features like pattern-matching, guard clauses, immutable data, green processes, and a complete lack of OOP make Elixir a great language to work with.