5 ms·
I used to be the guy who would say that people need to stop writing code which others can't understand, but then I migrated to, "why am I working at a company w
by splintercell 9y ago
I used to be the guy who would say that people need to stop writing code which others can't understand, but then I migrated to, "why am I working at a company where I need to lower the bar so much that making changes in a code you understand well takes ages".
I joined that school when I used FP for my own project (I use Elm, and RamdaJS+JS) and found how amazingly handling bugs and complicated logic became. This clearly came with a higher barrier to entry for other people to understand my code (but this cost only needs to be paid once, I look at other people's functional code and I got no problem understanding it btw).
I understand large companies where logic needs to be written so simply so that anyone can understand it (Python philosophy "Code is read a lot more times than it is written"), but they don't end up with fewer bugs, it's just a LOT LOT BIGGER codebase, with 5 million for loops, doing 1500 things in one for loop.
In fact, before I fully went to FP side, I started writing my JS code without using for loops or forEach. Even this simple change of writing code using map/reduce/filter/drop/reject/take etc made code lot simpler to maintain, reason with, and eliminate bugs.
- przemo_li 9y agoIf you stopped using native loops / forEach how do you handle iteration for the sake of creating side effects? +1 for including take/drop alongside map/reduse/filter
- splintercell 9y agoIn my experience, there is almost never a need for creating a loop on an array purely for the sake of side effect. For instance, if you want to write something on the log, then loop and collect everything into a single array (using map) and then perform the side effect with a single command (which is a lot more performant in most cases). For asynchronous side effects, create an array of promises using a map, and then run a Promise.all() on that array if you need to resolve all of them. But again, if your experience is different or in your requirements, it is not possible to create a map/reduce/filter transoformation for side effects, then I'd love to hear about it.