> On Jan 2, 2016, at 8:37 AM, Tino Heth via swift-evolution > <[email protected]> wrote: > >> >> Unless I missed something obvious, wouldn't placing "code that always has to >> run at the end" actually *at the end* not make more sense? Like this… > In most cases, you use defer for cleanup tasks - so it make more sense to > keep it at the source of the "problem": > > file.open(); defer { file.close() } > … > > Tino
This. It’s way easier to remember to do necessary cleanup tasks if you add the cleanup call right after the call that requires the cleanup. It’s also much easier to catch cases where someone has forgotten to do so. Separating the init and cleanup by large distances as in the old try/catch/finally mechanism makes it easier for things to get out of sync as the code evolves. Charles
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
