News for hackers. Stuff that matters.
Re:Avoid Else, Return Early (2013) by dragonwriter on Monday March 26, 2018 @09:36AM (#16678719)
The earlier version is clearly better and more clear, but presumes a language where if is an expression (and the actual return keyword isn't required, though “return if ...” is nearly as good.)

But if you are using a more imperative language where “if” is a statement, I think the merits of early return vs. use of an else clause are more balanced in this case.

Re:Avoid Else, Return Early (2013) by olavk on Monday March 26, 2018 @11:57AM (#16679811)
In C style languages you have the ?: operator though, which is basically if as an expression.
Re:Avoid Else, Return Early (2013) by dragonwriter on Monday March 26, 2018 @12:47PM (#16680268)
Functionally, yes, in terms of readability, not really. But, yes, for really simple cases like the example under discussion:

  return (a>=b) ? a : b
is probably the best option in those languages. The level of complexity at which the C ternary operator ceases to be ideal, I think, is lower than that of expression-if.