3 ms·
I don't have an aversion to if statements per se, but there's a logic to wanting to not over-use them or keep them out of code if possible: every code branch re
by jemmyw 4y ago
I don't have an aversion to if statements per se, but there's a logic to wanting to not over-use them or keep them out of code if possible: every code branch requires more work to unit test it. However, if you can restructure such that instead of using an `if`/branching you instead use whatever higher level structures the language provides then you only need to test the way it selects code to run is correct rather than multiple branches.
- flohofwoe 4y agoThere's just two options: either you compute both branches and ignore one of the results, or you decide upfront which result to compute (both are valid strategies depending on situation, target hardware etc...). In either case, there's a pretty high chance that the compiler turns your code into either of those options anyway, no matter what the input source code looks like. But just hiding if statements and loops under some high level functional mumbo jumbo just makes the code harder to understand for humans, and for the compiler harder to remove all the layers of 'expressiveness' and 'abstractions'.