Description
I propose a universal zero value with type inference. Currently nil is a zero value with type inference for pointers and built-in reference types. I propose extending this to structs and atomic types, as follows:
{}
would represent a zero value when the type can be inferred, e.g. in assignments and function call sites. If I have a function:
func Foo(param SomeLongStructName)
and I wish to invoke Foo with a zero value, I currently have to write:
Foo(SomeLongStructName{})
With this proposal, I could alternatively write:
Foo({})
For assignments currently (not initializations; post-initialization updates):
myvar = SomeLongStructName{}
With this proposal:
myvar = {}
This proposal is analogous to how nil is used for pointers and reference types.
The syntax allows type names and variable types to be modified without inducing extraneous code changes. The syntax also conveys the intent "zero-value" or "default" or "reset", as opposed to the actual contents of the zero value. Thus the intent is more readable.