3 ms·
I agree with the author. Elixir and Ruby share almost only the R letter in the name and some name of modules/method/functions. They are two very different langu
by pmontra 8y ago
I agree with the author. Elixir and Ruby share almost only the R letter in the name and some name of modules/method/functions. They are two very different languages.
A complaint of mine about Elixir is that `with` is a macro and not a statement of the language. That probably made it easier to implement but moving code inside/outside a `with` is a pain: transform the = into <- and add a comma at the end of the line. This is against programmer happiness.
The feature I love most is pattern matching in function arguments. It makes the code more readable by removing almost every single case/if.
- dnautics 8y agoI think generally the issue of when to use <- and when to use -> and when to use = is one of the few things about the language that makes my head spin.
- Exuma 8y ago<- is a comprehension, its like a for loop. -> is like for everything else like case and cond = is bind operator and is only used when you want to pattern match
- dnautics 8y ago<- is used for with as well and that is not a comprehension, and in feel way more like an = pattern match. -> is used in lambdas, which is kind of like case (but not cond).
- okbake 8y ago`with` is an oddball. It's a macro but it's also a special form that has unique syntax that's not used anywhere else. It's basically the only variadic function in the language and it doesn't fit IMO. It could have been implemented without needing the same special treatment with something like: with do x <- foo() y <- bar(x) z <- baz(y) blah(z) else err -> handle_err(err) end
- pmontra 8y agoActually I'd like this with x = foo() y = bar(x) z = baz(y) blah(z) else err -> handle_err(err) end No do (uselessly verbose, it litters all the language) and = instead of <- It should be normal code and take the else branch whenever there is any error, pattern matching included. The advantage is that the code can be indented in or out a with block, without any change. Much more convenient. Elixir also have a try/catch https://elixir-lang.org/getting-started/try-catch-and-rescue.html https://elixir-lang.org/getting-started/try-catch-and-rescue... > In Elixir, we avoid using try/rescue because we don’t use errors for control flow. We take errors literally: they are reserved for unexpected and/or exceptional situations.
- PopeDotNinja 8y ago> No do (uselessly verbose, it litters all the language) and = instead of <- It should be normal code and take the else branch whenever there is any error, pattern matching included. Using '=' insead of '<-' would break how with works. I can understand why one thinks the syntax looks weird. I avoid with when possible, but sometimes it's the easiest abstraction to use.
- jimbokun 8y ago"They are two very different languages." Then you later mention "programmer happiness". And I think an emphasis on "programmer happiness" is exactly what Elixir and Ruby share, and is probably the reason Rubyists are drawn to Elixir.
- brandall10 8y agoElixir was literally written by a Rails core team member as a response to issues he had in working on enterprise Rails apps. The Phoenix framework as well was written by a long-time Rubyist, and the book they wrote together, Programming Phoenix, reads in places like a treatise on lessons learned from working with Rails. So Rubyists (I myself have been one since 2011) are drawn to it because it essentially has been billed as a successor to Rails when you need to be concerned with highly concurrent, fault-tolerant, TDD-driven web apps. Most companies who have embraced it are former Rails shops... most devs who use it are former Rails devs.
- tiglionabbit 8y agoOr because the syntax is directly inspired by Ruby.