Instead of writing, def fn() = { val result = someExpression doSomethingElse() result } I've found myself writing code like, def fn() = try someExpression finally doSomethingElse() more, even when `someExpression` is pure. I'm not entirely sure how I feel about it.
-
-
Replying to @propensive
Try-finally triggers "resource handling" in my brain. Used this way is highly confusing to me. Also, if doSomethingElse() depends on someExpression it should be explicit imho...
1 reply 0 retweets 2 likes -
Replying to @lettisdotnet
I'd say it's a bit unintuitive, yes, based on the typical meaning of try/finally, but that's what made it interesting! Though is the use case actually so different from resource handling, if the key point is that a side-effect should always happen right after some code returns?
1 reply 0 retweets 0 likes -
Replying to @propensive
Yes, I guess side effects and resource handling can be seen as equivalent. I think struggle, however, with the example. Couldn't you just write def fn() = { doSomethingElse() someExpression } Or is someExpression used by the side effect in the try-finally?
1 reply 0 retweets 0 likes
I actually meant to say "didn't throw exceptions" rather than "pure" in the original tweet... trying too hard to save characters in my tweet. So the order is significant.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.