4 ms·
What do you mean defer isn't scope based in Go? (not super experienced Go developer)
by DanielHB 2y ago
What do you mean defer isn't scope based in Go?
(not super experienced Go developer)
- masklinn 2y agoIn Go, defers are function scoped not block scoped.
- TheDong 2y agoI mean, you just write all your scopes as `(func() { })()` in go, and it works out fine. Adding `func() {}()` scopes won't break existing code usually, though if you use 'break' or 'continue' you might have to make some changes to make it compile, like so: https://go.dev/play/p/_Gq4QYtyMmp https://go.dev/play/p/_Gq4QYtyMmp see, no other issues, works exactly like you'd expect
- DanielHB 2y agoRight, that makes more sense.
- devnull3 2y agomentioned in the article at [1] [1] https://thephd.dev/c2y-the-defer-technical-specification-its-time-go-go-go#scope-based https://thephd.dev/c2y-the-defer-technical-specification-its...