4 ms·
An ideal that you want to try to attempt to work through is the Principle of Least Power[0]. While is strictly more powerful than for, for is strictly more pow
by ItsMonkk 5y ago
An ideal that you want to try to attempt to work through is the Principle of Least Power[0].
While is strictly more powerful than for, for is strictly more powerful than foreach, foreach is strictly more powerful than map.
And yet 95% of the time, the power in map is sufficient. Therefore 95% of the time you should use map. When you encounter a foreach, you should be expecting non-purity. When you encounter a while, you know that it's doing some recursive operation that requires that power. If you have junior members of the team writing while loops where maps would do the senior members of the team who understand the nuance will take 10x more time to understand that code.
The same applies to statements/code blocks vs expressions. If all you are doing is assigning one value and have no other side effects, and you can do so in a way that's not overly nested, you should use an expression. If you can't, we have the more powerful statement/block structure to fall back on.
[0]: https://blog.codinghorror.com/the-principle-of-least-power/ https://blog.codinghorror.com/the-principle-of-least-power/
- jackdh 5y agoThank you for that link. I'd not seen it before but after reading the W3 article on it I wholeheartedly agree with it! It was interesting to find out how HTML was designed from the start to be simple and not a programming language on purpose for this reason!