4 ms·
I wrote a review of this book at InfoQ earlier this year: http://www.infoq.com/articles/the-go-programming-language-book-review http://www.infoq.com/articles/t
by alblue 11y ago
I wrote a review of this book at InfoQ earlier this year:
http://www.infoq.com/articles/the-go-programming-language-book-review http://www.infoq.com/articles/the-go-programming-language-bo...
There's a free chapter available from the book's website http://gopl.io http://gopl.io which should give you an idea of what the rest of the book is like. The intro goes into a little bit too much detail but if you gloss over that the remaining chapters are pretty else detailed. There are some nuggets distributed through the book but you could easily gloss over them if you were skim reading it, such as learning that exported identifiers begin with an upper case letter and those that are private are lower case.
- logingone 11y agoexported identifiers begin with an upper case letter and those that are private are lower case I'm not sure that should be considered a nugget, as much as a fundamental.
- alblue 11y agoYes, exactly - I would have expected this to be called out much more prominently than in the middle of page 28, especially when it defines 'exported' and then fails to have an index entry back to it.
- ape4 11y agofrom the book: The Body stream is closed to avoid leaking resources. I would have thought that a modern language would automatically take care of such things.
- jerf 11y agoI'm not sure exactly where you see that so I'm not entirely sure of the context (I tried looking in the first chapter), but a general problem with garbage-collected languages is that while the runtime will eventually get around to cleaning up unused resources, you don't always have guarantees about when. So you still generally need to close files when you're done with them, or you may run out of filehandles. I've encountered this issue in multiple languages, it's not Go-specific.
- ape4 11y agoIts on page 16 when they are showing how to download multiple urls concurrently - which is cool. In Firefox Ctrl-F "leak" works for me. http://www.gopl.io/ch1.pdf http://www.gopl.io/ch1.pdf
- danieldk 11y agoThis is a general property of most garbage collected languages - you don't know when a gc takes place (if ever) to run finalizers. For this reason Java has try-with-resources, C# using, Haskell bracket and Go defer. Note that you can attach a finalizer to a Go struct: https://golang.org/pkg/runtime/#SetFinalizer https://golang.org/pkg/runtime/#SetFinalizer
- dilap 11y agoLike others have mentioned, RAII-style stuff doesn't work so well with a GC language. Go does provide a "defer" statement, which cause a function call to execute when the current function returns. This makes it easy to visually co-locate resource acquisition and release, as well as ensuring the release code runs regardless of how the function is exited. It looks like this: f := os.Open("someFile") defer f.Close() // will run when current function exits It's easy and works well (IMO).
- incepted 11y ago> I would have thought that a modern language The only thing modern about Go is that it's just a few years old, but it's based on programming language concepts that were mainstream in the late 90s.