Hey Everyone
Brand new Elixir developer right here!
Excited to join a new community of developers, especially in such a new language. I figured I’d jump in by asking you all a question that I think is super interesting, which is:
In your opinion, what are 3 key differences between Elixir and Ruby?
Obviously there are a ton of differences since they’re completely different languages, but it seems like a lot of people (myself included) come to Elixir from a Ruby background, so it seems like this would be a good topic-especially for newbies like myself-that a lot of people could learn a thing or two from.
It doesn’t need to be 3, just threw that number out there. Looking for really anything and everything that those of you who came from Ruby found along the way, whether that’s big picture stuff like FP vs OO or really random small differences you’ve come across along the way. I’d love to hear it all!
I’ll get things started with a list of my own, keep in mind I just wrote my first line of Elixir three days ago so it’s all going to be super basic stuff, but here it is anyways:
- Variable Immutability
This has been a bit of a mind f*** for me. I’ve been trying to get in the Functional Programming / Elixir mindset by solving basic algorithms (without the help of Enum methods) and on more than one occasion I’ve felt completely trapped by the language. I’ll come up with like 6 different solutions, and each time I’ll think I’ve finally figured it out, only to realize half way through that the whole thing relied on mutating one obscure variable somewhere. Hopefully it comes more naturally soon.
- Lists are not Arrays
They might look look them and act like them but at the end of the day they are very different. Arrays are index based collections of values, whereas lists are Linked Lists, meaning every list is made up of two things, a single element (the head) and smaller list (the tail)
- Dot Notation on Maps
Ok so this one is super small but tbh it’s one of my favorites, and something that I’ve wished Ruby could do since like day 2 as a developer. When you create a map using atoms as keys (which is syntactically almost the exact same as creating a hash using symbols) you can access a specific key by using dot notation on the map ( key_value = %{ x: 1}; key_value.x #=> 1) instead of the Ruby way ( key_value = {x: 1}; key_value[:x] )