Avoid Else, Return Early (2013)
blog.timoxley.com
Avoid Else, Return Early (2013)
1–10 of 601 posts
Re: Avoid Else, Return Early (2013)
#2When I saw that, I imagined myself spending 10 minutes trying to understand why he does that. But maybe I'm not familiar with a JS best practice here.
Re: Avoid Else, Return Early (2013)
#3Re: Avoid Else, Return Early (2013)
#4Re: Avoid Else, Return Early (2013)
#5Re: Avoid Else, Return Early (2013)
#6Re: Avoid Else, Return Early (2013)
#7Re: Avoid Else, Return Early (2013)
#8"removing a whole line and more braces" - this is really fighting the wrong enemy. Code should be written in a way it is more readable, not shorter.
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
goto fail;
goto fail;
... other checks ...
fail:
... buffer frees (cleanups) ...
return err;
[0] https://www.dwheeler.com/essays/apple-goto-fail.htmlRe: Avoid Else, Return Early (2013)
#9Seems to me that there is quite a bit of commentary on this subject, and you can find it by searching for its typical solution: guard clauses[1]. [1] http://wiki.c2.com/?GuardClause
Re: Avoid Else, Return Early (2013)
#10I agree with much of the article (return early, errors management at the top, etc.). But won't returning a "wrong" value for the sake of one less line worsens the readability of the code? When I saw that, I imagined myself spending 10 minutes trying to understand why he does that. But maybe I'm not familiar with a JS best practice here.