100 Go Mistakes and How to Avoid Them |
Author: Teiva Harsanyi Overall I'd say that this book makes the case that it is simply the programmer not reading the documentation, or just not understanding it, that is the problem. I can't say that there is a single Go mistake as listed here that I would put at the door of the Go language. I would also say that there aren't 100 mistakes included as a lot of them are simply about making use of what is available. The book started life from a successful blog post of just 10 mistakes - which I think is a more practical number to deal with. I can certainly believe that there are 10 common mistakes that programmers make in Go, but not 100. The first chapter is called Go: Simple to learn but hard to master. I'd take issue with this statement as I think Go is a pussycat compared to languages like C++, Rust or even C. It is a small language that is easy to master - that doesn't mean you won't make mistakes. The first chapter dealing with "proper" mistakes is about code and project organization and again I disagree with emphasis here. The first mistake is using a declaration then using a declarative assignment. That is: myvar:=123 is equivalent to var myvar=123 This shorthand has long been known as a potential problem in Go and in this first mistake it is used to write a program that shadows a variable declared in an outer block. The suggested solution is to use a temporary variable with a different name and then assign it to the "global" before the block ends. This is silly as the problem is that the inner variable was declared as a new variable when in fact you wanted to use the global. Simply changing the assigment to the usual = rather than := solves the problem. At a few points I thought that a mistake was attributed to something that wasn't the real cause of the problem or that it could have been better avoided by understanding what is going on in a wider context. The rest of the book continues in the same way, outlining problems caused by the programmer not understanding the meaning or use of the language features. Many of the mistakes are familiar to any one working in almost any language - leading O for octal values, changing loop parameters within the loop,overlapping ranges and so on. Later chapters become increasingly general. For example chapter 8 is about concurency, something that Go is supposed to do well, and it covers the usual misunderstandings - concurrent is no parallel, concurrent is not always faster, race conditions and so on. There are also some that are Go specific like channels and contexts. Later chapters even venture into very general subjects such as testing and optimizaton. This is, of course, necessary if you need to find 100 mistakes. Listing mistakes as a way of teaching good Go programming might be a way that works for you, but personally I'd rather have a book that explains the principles of Go and perhaps programming in general. In this way the mistakes would never occur to you and if you saw someone else making them you would assume that they just didn't understand. Go isn't a language waiting to hijaack you into making mistakes, but if you don't take the time to understand it, what can you expect? If you are looking for a book to read that exercises your Go then perhaps this is the one for you, but even so keep in mind that it is showing you what not to do before putting things right. For I Programmer's recommendations of books on Go see Top Titles For Go Programmers in our Programmer's Bookshelf section. To keep up with our coverage of books for programmers, follow @bookwatchiprog on Twitter or subscribe to I Programmer's Books RSS feed for each day's new addition to Book Watch and for new reviews.
|
|||
Last Updated ( Wednesday, 19 February 2025 ) |