@iTod Keep related blocks of code together.
-
-
-
@mjtsai So it is a syntactical difference. Thanks. (AFAICT, this is the only significant difference besides cultural). -
@iTod Yes, mainly the syntax is much more convenient and readable. And there is the codegen difference because it’s not based on exceptions. -
@mjtsai Hm, you're fist to mention that. Is `try/finally` (with no `catch`) significantly different from `defer` from a codegen perspective? -
@iTod Haven't looked at the assembly, but I would assume yes because try/finally has to essentially catch and rethrow the exception. -
@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 defer -
@iTod Yes, if we're talking about runtime behavior, and we have zero-cost exceptions. But I thought we were talking about codegen. -
@mjtsai Ah, right. Interesting.
-
-
-
.
@iTod defer doesn't have to be used with try-catch; put your cleanup code right by the initialization. e.g. file open/close. -
@owensd I'm pretty sure you misunderstood me. I said `try/finally`, not `try/catch` nor `try/catch/finally`. - View other replies
-
.
@iTod that's what's better: there is only one cleanup mechanism. Promotion to a throwing function doesn't require moving code around. - View other replies
-
@owensd And as far as 'one cleanup mechanism' I'd say `try/finally` is even less conceptual overhead than `defer`, not to mention familiar. -
@iTod also, finally happens in order, defer happens on scope exit. -
@owensd I don't grok the difference there. Seems like both offer fine-grained ordering control. Maybe `finally` even finer control? -
@itod@owensd No matter how, when, or where the function returns, defer’s code will get called:https://gist.github.com/Cananito/f9f75076478665e7d2cc … -
- Show more
-
-
-
-
@Catfish_Man@joconor So the only diff is syntactic one? The cleanup code goes adjacent to code of your choice rather than after curly block -
-
@Catfish_Man@joconor Ok, so syntactic plus cultural difference. -
-
@Catfish_Man@iTod Because Apple has told people for decades that exceptions are only for fatal situations? - View other replies
-
@joconor@Catfish_Man Ja, that's an interesting point. Although it also falls under 'cultural'. Ok, thx.
-
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
David Owens II
Rogelio Gudino
David Smith
Jay O'Conor