Go structs are copied on assig... Note
Julia Evans

Go structs are copied on assignment (and other things about Go I'd missed)

The author, a casual Go programmer, encountered a bug that revealed a fundamental misunderstanding of how structs are copied during assignment in Go. This misunderstanding stemmed from the fact that structs are copied on assignment, not referenced, which led to unexpected behavior when modifying a struct after assigning it to another variable. The author was surprised by this behavior, as their experience with other languages led them to believe that variables were typically passed by reference. This misconception was further complicated by the author's understanding of pass-by-value and pass-by-reference in function arguments, which they had not extended to variable assignments. The author also discovered that sub-slices in Go share the same backing array as the original slice, meaning appending to a sub-slice can unintentionally modify the original. Additionally, the author gained clarity on the difference between value and pointer receivers in Go methods, understanding that pointer receivers are necessary when a method needs to mutate the struct it's called on. The author praised the "100 Go Mistakes" resource for its clear and concise format, which allowed them to quickly identify and learn from common Go pitfalls. Finally, the author listed other valuable Go resources, including "Go by Example," "go.dev/play," and static analysis tools like "staticcheck" and "golangci-lint."