Common Gotchas in Go
I think only #1 really counts as a gotchya. #3 is literally just "spend at least 2 seconds knowing what a slice is" (which you should do! there's only like 4 data structures in Go built in, so get to know 'em all). #2 is similar.<p>My favorite gotchya is that assigning a nil pointer to an interface will not give you a nil interface.<p>Once you know what's going on, it totally makes sense, but usually you don't start out with that deep an understanding of how interfaces work, and it violates natural-looking assumptions about algebraic equality, which makes for very easy counter-intuitive behavior.<p>Example:<p><pre><code>    package main

    import "fmt"

    func main() {
        var x *ErrorX = nil
        var err error = x
        if err == nil {
            fmt.Println("nope, this won't happen ")
        } else {
            fmt.Println("here's my non-nil error:", x)
        }
    }

    type ErrorX struct{}

    func (x *ErrorX) Error() string {
        return "hi i'm ErrorX"
    }
</code></pre>
<a href="https://play.golang.org/p/BB1b2_HDb6I" rel="nofollow">https://play.golang.org/p/BB1b2_HDb6I</a>