Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is not the same as Go's defer, as this honors scope; this is similar to D's scope guards (and hence the name of the C++ class...). In Go, when you use defer, the code in question is deferred until the end of the function, no matter in which scope you used the feature: this means that if you have a loop in which you use defer, everything is deferred until well after the entire loop finishes, not during each execution of the loop. This also means that Go has extremely... interesting?... behavior with relation to argument capture for the expressions used in a defer statement to make this even remotely sane. There are reasons the people who work on Go think this makes sense, but whether or not you agree with those semantics, the semantics implemented in this blog post are very different.


Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: