2 ms·
> The problem with "Make it an error to not initialise a struct field" is you lose source compatibility when adding new struct fields. If you allow the struct
by lmm 6y ago
> The problem with "Make it an error to not initialise a struct field" is you lose source compatibility when adding new struct fields.
If you allow the struct definition to specify a default value then the struct author can set default in the cases where there is a sensible default, and leave it compile-time incompatible in the cases where there really is no good default and the person doing the upgrade needs to make a decision.
- Cthulhu_ 6y agoThat is already possible by exposing a `New` function and making the struct itself unexposed; are you suggesting syntax should be added to provide default values to struct fields? Because there is high resistance (which I agree with btw) to adding additional syntax and constructs to the language.
- lmm 6y ago> That is already possible by exposing a `New` function and making the struct itself unexposed; I thought Go didn't allow functions with default argument values either?