4 ms·
Have to really disagree with the "comp" function example. No need to have "else" statements. The one with early returns and only "ifs" is succinct and good. Al
by DogLover_ 7y ago
Have to really disagree with the "comp" function example. No need to have "else" statements. The one with early returns and only "ifs" is succinct and good.
Also what is up with comparator function being used this way for most articles nowadays? If I am not mistaken "return a-b" is the much better solution and don't say that it is considered too clever :)
- panopticon 7y ago"return a-b" is susceptible to overflows and may lead to subtle bugs depending on your language.
- audience_mem 7y agoIn a sense it is the perfect example of "clear is better than clever", or perhaps "explicit is better than having buggy edge-cases"
- DogLover_ 7y agoThanks, did not think about that!
- city41 7y agoThe author states it's just an example and also says > This is reasonable when you’re dealing with functions which fit on a slide, but in the real world complicated functions– the ones we’re paid for our expertise to maintain–are rarely slide sized, and their conditions and bodies are rarely simple.