News for hackers. Stuff that matters.
Re:Avoid Else, Return Early (2013) by thomasahle on Monday March 26, 2018 @08:34AM (#16678351)
This particular refactor (changing `if (err) { return ... }` to `if (err) return ...`) didn't actually reduce indentation levels though. It only reduced the number of lines.
Re:Avoid Else, Return Early (2013) by moomin on Monday March 26, 2018 @09:44AM (#16678781)
Yeah, I’ll file that under “maybe don’t do that”.
Re:Avoid Else, Return Early (2013) by timoxley on Monday March 26, 2018 @01:05PM (#16680467)
what are the downsides
Re:Avoid Else, Return Early (2013) by moomin on Monday March 26, 2018 @04:52PM (#16682485)
In general terms, in C-like languages, mixing braces and semi-colons is horribly refactor unfriendly and bug prone. Meanwhile, sticking things on one line introduces a cognitive load that you might not want. (YMMV on the second point, but I’ve pretty strong views on the first.)