Post

I now firmly believe that the zero value concept for structs in @golang.org does more harm than good and have taken to running the exhaustruct linter through golangci-lint to prevent me from ever accidentally relying on it. I might write a post about this some day.

Consider what happens to code shown below when a new field is added to the ProductResult struct. To compound the problem, imagine a larger codebase where you're creating `ProductResult` values in a few places. Similarly imagine adding a field to `Product` and forgetting to fill it out before INSERT.

0 reposts0 likes

There are 2 kinds of structs in a codebase: 1. structs that act as configuration/options for components in the system and 2. structs that carry state to/from DBs, to/from http endpoints, etc... In the case of 1. there is some affordance for unset fields but with 2. it can be really bad to miss one.