2 ms·
The functional style that you show certainly has multiple points where a value is returned, so you could call it "early return"; even if as a syntactic shorthan
by SideburnsOfDoom 9y ago
The functional style that you show certainly has multiple points where a value is returned, so you could call it "early return"; even if as a syntactic shorthand the keyword "return" is omitted. This is common across a lot of functional languages.
- masklinn 9y ago> The functional style that you show certainly has multiple points where a value is returned, so you could call it "early return"; It's not "early return" any more than: function(err, results) { if (!err) { // handle results } else { return handleError(err) } }
- SideburnsOfDoom 9y agoRight, though I was thinking of other examples of functional match style and returning a value. As seen in in Haskell, F# Rust etc. e.g. https://doc.rust-lang.org/book/second-edition/ch06-02-match.html https://doc.rust-lang.org/book/second-edition/ch06-02-match.... So value_in_cents can return a value of 1, 5, 10 or 25. Saying that it "does not have a return statement" might be truish - but the fact that the "return" keyword is not needed to return values is just syntax. Saying that there's no early return / multiple exit points is not so much. To my eye there are 4 places where that function can return a value. And the cases might not be simple numbers making the whole thing an expression, later examples on that page show how the cases can differ in side-effects.