5 ms·
For me, the benefit vs OO is that everything is explicit. If I'm calling into a function from another module, it's almost always clear which other module -- if
by toast0 7y ago
For me, the benefit vs OO is that everything is explicit. If I'm calling into a function from another module, it's almost always clear which other module -- if I need to see what it does, I can go look and the code is likely to be there. Compared to something in OO where I've got an object to call a method on, and it may actually be an object that extends/implements making it much harder to find code (IDEs can often help, if you've taken the time to setup the IDE).
You can call into a module with a variable, but it's rarely done, outside of some specific types of code interaction (ex: structural event loop processing like gen_server takes a Module to callback into).
Of course, when sending messages to processes, there's not really anything in code to indicate where those will be processed, and I don't know that IDEs help there either. Usually, code organization helps, but it's not required.
Caveat: my experience is with Erlang, not Elixir, but should generally apply.
- princevegeta89 7y agoSpot on! I did some work on OTP and it seemed to be neat. I did learn Go just to compare how easy/fun it would be to work with. I liked Go but I came back to Elixir because of pattern matching, minimal configuration and readable semantics. Not to mention, there's not much boilerplate to deal with and we've got useful control structures like the very readable `cond`s instead of if {} else if { } blocks (Although you can use these, it is generally discouraged in Elixir). I will tell you that being pushed towards writing "cond" s and "when"s, "with"s has guided me towards achieving a better and more readily understood codebase.
- filmor 7y agoThe explicitness of Erlang is exactly what Elixir is lacking. A /lot/ is done via macros. This makes it really easy to build domain-specific language extensions, but it also means that you'll have to learn what they are doing to fully understand the code. In Erlang, the few simplifications you get are very local (as long as you don't apply a parse_transform on your whole project, which is rarely a good idea).
- Communitivity 7y agoI agree, and I'm a rarity maybe, because I think it is much easier to understand and debug Elixir if you learn Erlang first. You don't have to, in order to code in Elixir, but understanding what was going on under the hood made it much easier for me to work with Elixir.
- pmontra 7y agoI understand how that could be a problem. However it never was with the countless DSLs I saw in Ruby. The trick is never write one. Only use the ones of widely popular projects. I never wrote a macro in Elixir (only for experimenting with them), nobody ever did in the projects I worked on and I'm perfectly happy with that. On the other side everybody uses macros, mainly with/do/else. I wish they implemented it as keywords of the language. They could probably have spared us the annoyance of converting code from = to <- and comma everytime it is moved inside a with and viceversa. That's the part of the syntax that I like less.
- dnautics 7y agowhich DSLs are you talking about, as far as I know the only truly heavy-handed DSLs in common use in the Elixirverse are Phoenix, Ecto, and ExUnit. - I'll say that Phoenix Macros somewhat annoy me, but i can see why they would be useful for someone with a Rails background (which I am not). - I'm quite happy with not having to think about how Ecto marshals its queries into SQL. Life's too short for that. - Is it really such an impediment to code grokking to have a `test "label" do...end` construct?