4 ms·
In what way is Elixir's syntax like Ruby's? It has "end" on blocks and string interpolation with "#{whatever}", but everything else is different. It's about as
by cosarara 7y ago
In what way is Elixir's syntax like Ruby's? It has "end" on blocks and string interpolation with "#{whatever}", but everything else is different.
It's about as close to Ruby as Ruby is to Python (which is to say, not much).
- onlyrealcuzzo 7y agoI think it really helps that you can write mostly functional code in Ruby by just chaining higher-order array functions, and you can use Pipes in Elixir to do this almost identically -- when you consider the fact that all the higher-order array functions have identical or very similar names and parameters in the two languages. My Ruby code is like 95% chained higher-order array functions. My classes almost never have state. I'm basically writing functional code, and it seems like this is a pretty common paradigm in Ruby. I will say this was HEAVILY influenced by learning Elixir. When not taking external libraries into account, my Elixir code (at least to me) seems almost identical to my Ruby code. I think Python and Ruby are very close. But I personally think list comprehensions are un-intuitive and you can't easily chain higher-order array functions in Python. So although I feel the spirit of my Ruby and Python code is identical, in no way do they look and feel identical. In the same way, I think my Elixir and Python are quite different. Sample size of 1. I know. Just thought I'd share.
- cosarara 7y agoThanks for sharing! I think though that what you are referring to is not syntax but semantics. On both places you are chaining HO array functions, so the algorithm is pretty much the same, but the syntax you use is different in both places (pipes, dot).
- pseudalopex 7y agoPython's ist comprehensions are just set builder notation with English keywords.
- yellowapple 7y agoHaving done lots of development in both Ruby and Elixir (both professionally and on my free time), I'd say the only substantial differences boil down to the following: - Elixir has |> instead of method chaining - Elixir uses "do [...] end" consistently for blocks (as opposed to Ruby omitting the "do" in front of function/module/class/etc. bodies) - Elixir supports Erlang-style tuples on a syntax level while Ruby (AFAICT) does not - Elixir supports Erlang-style pattern matching / destructuring while Ruby (last I checked) does not - Elixir's a fair bit stricter about differentiating zero-argument function calls from variables (i.e. if it's ambiguous it'll complain) That is to say, Elixir's syntax descends directly from Erlang and Ruby, just as Ruby's syntax descends directly from Eiffel and Perl, and it shows rather strongly. That should be unsurprising, given that Elixir is the creation of a (former?) Rails maintainer.