3 ms·
I see a lot of Elixir lovers but I just can't wrap my head around a lot of the idioms. Is it bad I much prefer loops to reduce? Also modelling complex domains t
by bestinterest 6y ago
I see a lot of Elixir lovers but I just can't wrap my head around a lot of the idioms. Is it bad I much prefer loops to reduce? Also modelling complex domains things just flow better in my brain with OOP, whenever I go to draw things I put them in boxes with as little state as I can.
I would love love love to see two people approach the same exact problem with OOP and FP and see the rewards of both.
However I really love pattern matching from Elixir real game changer of a idea, excited to see it come to Java and Ruby soon and the lightweight threading models come to both of those languages also.
I always preferred Brian Gotez's argument that you should be functional within objects. https://www.youtube.com/watch?v=8GWZE2Y2O9E https://www.youtube.com/watch?v=8GWZE2Y2O9E
- pmarreck 6y agoEven in Ruby, no one uses loops, they use Enumerable. Eliminates off-by-1 errors! Reduce (inject, etc.) are tricky to understand at first but once you do, you realize the power in it. Granted, it’s harder to understand than loops, but loops with iteration and mutability get you into a lot more trouble. It sounds like you’re simply not over the learning curve yet.
- dragonwriter 6y ago> Even in Ruby, no one uses loops, they use Enumerable. Enumerable#each is quite deeply equivalent to a for…in loop. But no one uses for loops in Ruby because not only are they basically an alternate syntax for Enumerable#each, but they became non-idiomatic because in earlier versions (through at least 1.8.x, IIRC; I think this may have been resolved by the switch to YARV in 1.9) “for” had some implementation inefficiencies which made it notably slower than #each.
- lillesvin 6y ago> Is it bad I much prefer loops to reduce? No. That's the reason that we have multiple different tools at our disposal. :) My rule of thumb has always been to use the tool that I, myself, find more effective—not what others say would be the most effective in an ideal world where I know everything about every programming language in existence. That means that I've written a handful of shell-scripts in PHP, some CLI-tools in Ruby (that would probably run a lot faster in Go), and a couple of "API"s in Bash.
- dragonwriter 6y ago> Is it bad I much prefer loops to reduce? It…depends what for. There are things loops are more clear representations of intent for, there are things map is a more clear representation of intent for, and there are things reduce is a more clear representation of intent for.
- sullyj3 6y agoReduce is just a loop that's already been written for you!
- mercer 6y agoFWIW I'm balls-deep into Elixir, pardon my language, and I almost never write recursive functions.
- bestinterest 6y agoDo you have any tips for people coming from Ruby land on how to model things with a more functional approach? For example I've been watching some of 'On Writing Software Well' series https://www.youtube.com/watch?v=D7zUOtlpUPw https://www.youtube.com/watch?v=D7zUOtlpUPw by DHH and found it really useful for OOP land. Also any idea on how StimulusReflex / new Hotwire compares to Phoenix LiveView if you have had a chance to look at it yet?