3 ms·
So, the author thinks this is harmfull?: var area= ( width, height ) => width * height; If not, it is just clickbait for me.
by twii 9y ago
So, the author thinks this is harmfull?:
var area= ( width, height ) => width * height;
If not, it is just clickbait for me.
- Clubber 9y agoIf I'm understanding you correctly: It would be harmful if you were calculating something subject to change, like, say price. price = (cost) => cost * 1.10; And you sprinkled that throughout your code. The problem arises when the business says they want to be able to change the logic so that it lowers the price for customers that have subscribed over a year. Now you have to change the logic everywhere that shows up, rather than having a single function where you change it once: function decimal Price(cost) { .. } That in essence, is why DRY is important: code maintenance & refactoring. Even your example it could be dangerous: var area= ( width, height ) => width * height; What if the business was making sandboxes and they wanted to be able to add a short wall around it so cats have a harder time using it as a bathroom. It would then be: var area= ( width, height ) => (width + 1.0) * (height + 1.0); Again, if you had sprinkled that throughout your code, you would have to search and find every instance of that and change it. This is also harder to test, because if you miss one, chances are, it won't show up immediately.