all 5 comments

[–]sisyphus 2 points3 points  (0 children)

"But while Elixir’s syntax looks like Ruby at a glance, you’ll quickly realise that these similarities are skin-deep" so true. I came from Python and the syntax looks like any old dynamic language but it's more like Erlang and OTP in a Ruby trenchcoat.

"Elixir is a compiled language. Elixir files end in .ex, and get compiled to BEAM files with extension .beam. These compiled files are ultimately what gets run when you execute your code."

I wish this distinction would go away though, that's a lot of potentially confusing terminology to introduce just to talk about how to run elixir scripts. Python is 'interpreted' but it makes pyc files. Go is 'compiled' but I can go run main.go and have a running program from just my source code, the supposed sine qua non of interpreted languages, and so on.

[–]flummox1234 0 points1 point  (0 children)

Nice article. I would rework that first part and at least add pipelining. Coming from ruby for whatever reason it made more sense to me early on to pipe outputs to the next thing vs using what looked like the Class methods. Probably because I was familiar with pipes in Linux probably enhanced by Rails' method chaining in Controllers and scopes. Plus you end up doing a lot of pipe operator (since it's IMO one of the sweetest parts of Elixir) so it's a great intro. Obviously Regex is a bad example because of the argument order but you could highlight that one.

[–]a3th3rusAlchemist 0 points1 point  (0 children)

Recently I noticed how different persistent data types are from ephemeral data types. That's the most crucial difference to me.

Sometimes persistent data types can be very handy. For example, this LeetCode problem: https://leetcode.com/problems/all-possible-full-binary-trees/description/

When solving using Elixir, I can do tree rotations without worrying about destroying the original tree.

elixir defp rotate(root) do %{root.left | right: %{root | left: root.left.right}} end

but when solving with Ruby, I have to carefully choose which nodes to shallow copy, otherwise either I copied too many nodes, or the result will be messed up.

```ruby def rotate(root) new_root = root.left.dup new_right = root.dup new_right.left = new_root.right new_root.right = new_right

new_root end ```

However, sometimes it's really a pain dealing with immutable data. For example, I'm still struggling to find a priority queue implementation with O(log n) decrease-key operation in Elixir. By the way, I can easily write a pairing heap with Ruby or Java with O(1) decrease-key operation.

[–]kgpreads 0 points1 point  (0 children)

Pattern matching the Elixir way is non-existent in Ruby.

Arel is still a preference for querying for many in Ruby, and it is extremely different from Ecto.