Proposal: embedded named inline types (type namespacing) #38245
Labels
FrozenDueToAge
LanguageChange
Proposal
v2
A language change or incompatible library change
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
Milestone
Go allows us to declare struct types with embedding other struct types. They can be either named or anonymous:
Anonymous inline embedding
is useful for data-only struct when you know you won't need to add methods, and won't use these types separately as function arguments, etc.Named embedding
does a great job, you can use these structs separately and add methods to them. But I can see a minor drawback: polluting the scope with type names, so requiring of manual namespacing.Example that highlights the problem:
It can be not the best example, but the idea is that we have to namespace the type names. And if level of embedding is more than 3-4 it makes ridiculously long names.
Idea behind proposal is allowing
Named inline
embedding. A want-to-be example:so here we have 4 types:
Person
,Company
andPerson.Contacts
andCompany.Contacts
.We can still create general type
Contacts
, and it won't cause any problem to*.Contacts
The text was updated successfully, but these errors were encountered: