3 ms·
Also read the official blog post on defer: https://blog.golang.org/defer-panic-and-recover https://blog.golang.org/defer-panic-and-recover It covers about half
by jitl 9y ago
Also read the official blog post on defer: https://blog.golang.org/defer-panic-and-recover https://blog.golang.org/defer-panic-and-recover
It covers about half of these gotchas by laying out how the defer statement works in plain English. The other half (like how closures work inside loops in Go) are covered elsewhere in the language tour.
I do really like the visualizations! Makes it very clear how these mechanics work.
- jerf 9y agoThe content is good, and it is accurate, but even though defer can be a bit tricky this blog post series seems to literally be describing the entire semantics of "defer" as "gotchas". It's not that tricky!
- inancgumus 9y agoWell, it depends. Upgoing posts will go deeper on defer.
- inancgumus 9y agoThanks! That post definitely a must read. Btw, the first part was more advanced (but again for beginners and intermediate gophers) -> https://blog.learngoprogramming.com/gotchas-of-defer-in-go-1-8d070894cb01 https://blog.learngoprogramming.com/gotchas-of-defer-in-go-1...