I'm curious: What's better about Swift's `defer` than `try/finally` in ObjC or Java (or virtually any other language since 1990)?
-
-
@iTod Keep related blocks of code together.0 replies 0 retweets 0 likes -
@mjtsai So it is a syntactical difference. Thanks. (AFAICT, this is the only significant difference besides cultural).0 replies 0 retweets 0 likes -
@iTod Yes, mainly the syntax is much more convenient and readable. And there is the codegen difference because it’s not based on exceptions.0 replies 0 retweets 0 likes -
@mjtsai Hm, you're fist to mention that. Is `try/finally` (with no `catch`) significantly different from `defer` from a codegen perspective?0 replies 0 retweets 0 likes -
@iTod Haven't looked at the assembly, but I would assume yes because try/finally has to essentially catch and rethrow the exception.0 replies 0 retweets 1 like -
@mjtsai Hm, that's interesting. So they're only different if an exception is thrown. But in non-exceptional case, it should be same as defer0 replies 0 retweets 0 likes
@iTod Yes, if we're talking about runtime behavior, and we have zero-cost exceptions. But I thought we were talking about codegen.
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.
Todd Ditchendorf
Michael Tsai