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
proposal: Go 2: improve the initialization of embedded anonymous struct #29438
Comments
I think this is a subset of #12854. |
Yeah. And I think the main difference is:
|
I'm struggling to see the value in this. If you use the same anonymous struct twice inside another struct, it's not a big deal just to duplicate it. If it is a big deal, then why not define it as a named struct instead? It seems odd to say "this struct is so onerous to repeat that I need to name it, but only within the scope of this other struct it's embedded in". |
@bitfield I think it can be an issue in systems that deal with deeply nested structs (e.g. nested JSON API responses). In those cases, it's not always friendly to declare each nested struct as a named struct. |
Let's merge this into #12854. The ideas are very similar. |
@ianlancetaylor I think you meant #12854 :-) |
@networkimprov Yes, thanks. Updated comment. |
Problem
Now it's very redundant to initialize an embedded anonymous struct. We have to re-define the same anonymous struct in the assigned value. For example,
We have to re-define the same anonymous struct
struct {first string; last string}
again in the value which is unnecessary cause we have already known the definition of the anonymous struct type.Solution
Remove the unnecessary re-defined anonymous struct in the value. For example,
or
The text was updated successfully, but these errors were encountered: