←back to thread

Go is still not good

(blog.habets.se)
644 points ustad | 1 comments | | HN request time: 0.21s | source
Show context
akoboldfrying ◴[] No.44983318[source]
defer is no worse than Java's try-with-resources. Neither is true RAII, because in both cases you, the caller, need to remember to write the wordy form ("try (...) {" or "defer ...") instead of the plain form ("..."), which will still compile but silently do the wrong thing.
replies(1): >>44983476 #
xyzzyz ◴[] No.44983476[source]
Sure, true RAII would be improvement over both, but the author's point is that Java is an improvement over Go, because the resource acquisition is lexical scoped, not function-scoped. Imagine if Java's `try (...) { }` didn't clear the resource when the try block ends, but rather when the wrapping method returns. That's how Go's defer works.
replies(1): >>44983519 #
akoboldfrying ◴[] No.44983519[source]
Can't you create a new block scope in Go? If not, I agree. If so, just do that if you want lexical scoping?
replies(2): >>44984074 #>>44985664 #
1. gf000 ◴[] No.44984074[source]
You have to create an anonymous function.