Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I disagree with #3.

If I change a data structure I want the compiler to tell me exactly which parts of the code I should rethink. I do not want it to silently initialize new fields with automatic values, as that may invalidate some of my invariants.

Confusingly, it seems that the author is aware us this issue, as he acknowledges exactly this issue #6, and provided a recommendation for easier debugging of such situations.



The idea is that, when you add a new field to the struct, the behavior should not change if that field is given its zero value. Thus, all the rest of your code continues to work as it did before.

If you change the code such that the zero value of that field makes the code behave differently, then yes, it's your responsibility to go find all the places that use the struct and update them. However, thanks to static typing and nice namespaces, that's trivial.


Zero values in struct initialization (and other places) is a routinely encountered behavior in go.

http://golang.org/ref/spec#The_zero_value


I'd present it as options going either way so the reader knows which to choose. There have been times when I would use either.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: