What's the best approach for us to provide struct initial values:
can we support hard coded values?
can we support calculated values? can we use values of other fields?
can we accept values as arguments?
require accepting values is problematic because it will break backward compatibility of no argument initialization in zero value of structs, reflect.New and other use cases. can we work around it somehow?
I had something like this in mind:
private type Foo struct {
private fieldA string // zero value
private fieldB string = 1 // hard coded value
private fieldC string = self.calculateFieldC() // calculated value
}
func (f *Foo) calculateFieldC() string {
return f.fieldB * 3
}
What's the best approach for us to provide struct initial values:
require accepting values is problematic because it will break backward compatibility of no argument initialization in zero value of structs,
reflect.New
and other use cases. can we work around it somehow?I had something like this in mind:
More context in this blog post section.