DEV Community

[Comment from a deleted post]
Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn

Ultimately, almost every difference between the two comes from the fact that FP preferentially wants all data to be immutable, while OO wants it to all (or mostly all) be mutable. This in turn favors pure functions and separation of code from data for FP, and side effects and unification of code and data for OOP.

However, that has less impact than you might think on the actual algorithms and data structures that get used, it's mostly just differences in how they're implemented. The same applies to procedural code, it's largely the same algorithms and underlying data structures, just differences in how they're implemented. And that's perfectly fine, especially since you can often implement the same algorithm multiple ways without even switching paradigms.

On that note, one of the most helpful things for me as I've been learning Elixir has been to work on re-implementing things I already know how to do in other languages in Elixir. Because I already know the algorithm and have implemented it before, I don't have to focus as much on the algorithm itself, and can thus focus more on the implementation without having to worry about potentially getting the algorithm itself wrong.

Also, one big thing to remember, iterative looping doesn't inherently require mutability, despite what many FP proponents claim. You can do procedural-style loops just fine in Elixir using Enum.reduce/3 (or Enum.reduce_while/3 if you may need to bail early), it just requires a different way of thinking about the loop itself, and slightly different handling of the loop output.