DEV Community

Discussion on: Write less code

Collapse
 
lioobayoyo profile image
lioobayoyo

I agree your example is typical of useless verbosity. I find that the problem with the above 5-lines code is not so much that the one-line code is equivalent, it is more that the 5-line code is redundent, it repeats itself somehow.

Note that in some languages, it might not be equivalent (in JavaScript for instance, the latter returns an expression that could be of any type, while the former returns only true or false, the two possible boolean values.

return Boolean(expression) or return !!expression would be the JavaScript equivalent of the former expression.

However, if you have a nice tricky formula that covers several cases, and you use your clever formula instead of a clear if - else if - else statement, you might give a hard time to your future colleagues that will have to maintain and augment your code. This other person could be you some months or years later !