Adding Go's Defer to the TypeScript Compiler

(healeycodes.com)

11 points | by healeycodes 3 hours ago ago

3 comments

  • throwaway81523 an hour ago

    Article describes try/finally as a hack to get the effect of defer, but it looks to me like it's the other way around? Try/finally is more traditional, in one form or another.

    • kaashif 13 minutes ago

      If the idea of computers is that they remember stuff for you and do stuff for you, then both try/finally and defer seem like hacks to work around not having RAII like e.g. Rust or C++ where resources are closed/disposed of/deallocated automatically.

      Try X finally dispose of all resources. X, defer clean up X. Or how about just X and cleanup is done automatically, with the author of the resources deciding what is needed to clean X up.

    • Rohansi 38 minutes ago

      It's also necessary here because TypeScript has exceptions and you'd expect your `defer`s to execute even when an exception is thrown.