5 ms·
There's basically data and functions, so 4 wouldn't really have any methods attached to it and instead you'd just call Number.even?(4). Purely psuedo code examp
by brightball 10y ago
There's basically data and functions, so 4 wouldn't really have any methods attached to it and instead you'd just call Number.even?(4). Purely psuedo code example.
It's a deep subject but one of the biggest things is that it's virtually impossible to end up with the untenable monolith that many ruby apps eventually grow into. Since you aren't dealing with crazy inheritance trees attached to data separating things out really just becomes moving code around.
I do both Ruby and Elixir code right now. There are times when I like the convenience of Ruby for command line scripts or monkey patching a quick modification for a 3rd party library...but there are other times when you hit problems that you just can't solve effectively without rewriting in something else and that gets annoying. That's one of the reasons you see so many posts about moving from Ruby to Go or Elixir because both languages are much better at Ruby's weakest points.
But it's always worth noting that Ruby got those projects to market with maturity and helped them grow customer bases with enough traffic to JUSTIFY a rewrite. What gets people so excited about Elixir is that you lose very little in the development time department for full stack while avoiding the long term complications due to the language rules. All that said, it makes you think about problems differently which will be a challenge for people at first.
- pawelduda 10y agoOr like this, thanks to the pipe operator 4 |> Integer.is_even Above can be even shortened if you import Integer module: import Integer (...) 4 |> is_even
- _asummers 10y agoCollectively at work, we've abandoned the use of import, except when importing DSLs (e.g. Ecto) in favor of explicit function calls or alias. If we do need to use import, we use explicit "import Ecto.Query, only: [from: 2]", so that it's clear where a function is coming from into the namespace. Relatedly, unless otherwise necessary, __using__ macros through our code do not import modules, because it's surprising when something is in scope for no real reason. We often inline the third party __using__ macros to eliminate this.
- pawelduda 10y agoAnd I completely agree with this, I have just posted the above example to show that Elixir's syntax can be concise too in case anyone would want that. :) What Elixir has changed for me, is that I now value the explicitness of my code more than ever. And thanks to this, I aim to write code like this in other languages I use on daily basis (Ruby, Python).
- _asummers 10y agoFor sure. I just think a lot of new people get caught up in the ability to be concise for self that they forget about the expressiveness for others. Unrelated, we also abandoned 1 pipe pipelines, and instead prefer "function(arg)". Just looks better to us, despite the minor maintenance cost of having to change it if you convert to multiple pipes.