6 ms·
Sometime I wonder why Elixir tries too hard to have Ruby syntax. Erlang: loop_through([H|T]) -> io:format('~p~n', [H]), loop_through(T); loop_through([
by namelezz 11y ago
Sometime I wonder why Elixir tries too hard to have Ruby syntax.
Erlang:
loop_through([H|T]) ->
io:format('~p~n', [H]),
loop_through(T);
loop_through([]) ->
ok.
It seems convenient to use ';' to separate multiple definitions of a function compared to using 'end' in Elixir(function definition continues in the next block)
Elixir:
def loop_through([h|t]) do
IO.inspect h
loop_through t
end
def loop_through([]) do
:ok
end
- aaron-lebo 11y agoI believe, like Steve Yegge has said elsewhere, that programmers are lame, (and now paraphrasing) because they refuse to touch things that look odd. Erlang's syntax may be more efficient, but a lot of people won't touch it becuase the syntax is unfamiliar. Elixir has a huge advantage in this. It might not matter to you specifically, but in the realm of adoption that is huge. And honestly I really enjoy the syntax...
- bpicolo 11y agoI mostly enjoy the syntax. Kind of hate that they made parentheses for function calls optional, especially since no-parentheses has ambiguous cases that behave weirdly (like with chaining syntax). Should be enforced. Also, all the different import-related keywords are pretty confusing. Maybe that's improved though
- vvanders 11y agoDoes do/end make it much easier to build macros with Elixir? I don't find either syntax to be off-putting but that's just me.
- yelnatz 11y agoMuch of the Ruby influence is because the creator of Elixir (José) was previously from the Rails core team.
- crymer11 11y agoStill pretty new to Elixir, so I welcome any suggestions, but from my understanding (and based on Elixir's guides [1]), I think that the more idiomatic way to approach this is to avoid writing such a loop_through/1 function and instead just use: Enum.each(<the list>, &IO.inspect(&1)) or likely <series of data transformations resulting in list> |> Enum.each(&IO.inspect(&1)) Both return the :ok at the end of the loop, so Enum.each/2 looks to be functionally equivalent. 1 - http://elixir-lang.org/getting-started/recursion.html http://elixir-lang.org/getting-started/recursion.html
- rdtsc 11y agoTrue. I personally like Erlang's syntax more. I like single assignment variables, I like the structure and feel of it and so on. But Elixir is great too. I am glad it is there and is taking advantage of the BEAM VM. It definetily appeals to many Ruby-ist or those who used Python and are otherwise scared by a different syntax.