Re:Things Rust shipped without
by 88e282102ae2e5b on Friday July 03, 2015 @04:18PM
(#9827715)
Why "might as well"? Things can be optimal in some places and suboptimal elsewhere.
[ Parent
| on HN ]
Consistency is valuable. If some blocks have different rules to other blocks that's a real downside.
Re:Things Rust shipped without
by 88e282102ae2e5b on Friday July 03, 2015 @05:26PM
(#9828040)
That's true, but they're so syntactically different that I can't imagine a scenario where someone is asking whether it's closures or functions that you're supposed to use return statements in.
Re:Things Rust shipped without
by Sanddancer on Friday July 03, 2015 @09:28PM
(#9828776)
A foolish consistency is the hobgoblin of little minds. Sometimes a variation in rules allows for more clarity -- one could set their editor to make return a different color, for example, making it easier to glance at program flow. Then again, I'd argue that closures should allow returns too, like they do in C#. I'm an adamant supporter of the explicit camp -- when you have to debug things at 3 in the morning, sometimes that extra little bit of context can make things blindingly obvious.
I find the way it works in scala very nice - a block is just an expression that evaluates to the last statement in the block, and idiomatic code never uses "return" anywhere. Even e.g. a function definition, you can replace the block with a single expression if it's more convenient. I agree with being explicit but I don't think return actually makes things any more explicit (if you're talking about an editor highlighting, the editor knows which line is the value of the block, with or without a "return") - rather it's just syntactic ceremony. It's surprising how much difference having very low-overhead closures makes - you can make so much of your program simpler, because it's not a problem if a caller needs to make a slight modification to something.