3 ms·
Lots of languages will implicitly return the final expression— I feel like that's a decent compromise. Not quite as magical as an actual named variable that jus
by mikepurvis 4y ago
Lots of languages will implicitly return the final expression— I feel like that's a decent compromise. Not quite as magical as an actual named variable that just exists, but not as clunky as needing as explicit `return` every time.
- tsimionescu 4y agoHonestly, I don't like that style for languages which allow multiple side-effects as well. For example, (progn (print "something") 0) Is honestly pretty ugly from my point of view.
- mikepurvis 4y agoSure, definitely, and in a case like that (say, in rust), I would just put an explicit `return` in. But there are lots of other scenarios where the result is naturally being returned by the final expression and it's quite convenient to elide the extra keyword.
- Falkon1313 4y agoI always disliked implicit returns, and over the years and having dealt with many more codebases, some quite large, I've learned to dislike any implicitness. I would much prefer that you must explicitly return a value (even if it's through an implicitly declared 'Result' variable) rather than just 'try to guess what happened here, in this long function with lots of expressions'. There are a few exceptions, like Forth, where you really have to keep the current state of the stack in mind at all times anyway. Those exceptions naturally tend toward very small functions. Most languages don't, and the result is inevitably difficult to understand bugs.