News for hackers. Stuff that matters.
Re:Anti-If: The missing patterns (2016) by yoodenvranx on Wednesday June 27, 2018 @12:24PM (#17409448)
Thank for posting this! I recently had quite a few discussions about this topic with people who insist to _always_ use if/elseif/elsif/... constructs in such situations. I tried to argue that in most situations a "if (a) {return}; if (b) {return}; do_c()" construction is much easier to understand but I had only little success convincing them.
Re:Anti-If: The missing patterns (2016) by Flow on Wednesday June 27, 2018 @02:49PM (#17410738)
I always say that if you know the answer, why convolute the code? Just return the damn answer and we're done here.

I see these early returns as a list of assumptions. It helps making them nicely lined up, with perhaps some comments before each, and an empty line between them.

And then when you get below to the, now non-nested, code that actually does some work you have a smaller mental burden needed to understand what is actually done.