Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struct Initial Values #1

Open
avivcarmis opened this issue Aug 8, 2022 · 0 comments
Open

Struct Initial Values #1

avivcarmis opened this issue Aug 8, 2022 · 0 comments

Comments

@avivcarmis
Copy link
Contributor

avivcarmis commented Aug 8, 2022

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 can we do about this self?
  • does it answer all requirements

More context in this blog post section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant