4 ms·
But it's not the last line of a function, though, is it? Put an if statement in there, and it can be literally any line of the function. Sure, you can still wor
by user-the-name 5y ago
But it's not the last line of a function, though, is it? Put an if statement in there, and it can be literally any line of the function. Sure, you can still work out which one, but it gets more difficult.
And, even if it were the last line of the function, you are still not communicating clearly whether the function is meant to return a value at all or not. This both hurst readability, and makes it easier to accidentally introduce bugs.
- slver 5y agoIt's just inescapable that your argument in fact requires explicit returns in mainstream languages whether you return value or not. Because the "does it return value or not" question doesn't sit in expression languages. They always return value.
- user-the-name 5y agoWhy do you say that as if it is not a problem in itself?
- PoignardAzur 5y agoYeah, in practice I have this problem with Rust sometimes. If the returned value is a single line, it's easy to see what is being returned. If it's a 10-lines if/else, and you don't remember the function's return type, and you're not sure how many layers of control flow you're at, etc, it gets a little ambiguous. You can mitigate that with good coding practice, though. There could maybe even be turned into lints.