-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
spec: consolidate the definition of "defined types" #45587
Comments
As far as I can tell, this seems to be more about clarity and cleanup than proposing something new. Is that right? |
This is about clarity of the spec, I believe. Fundamentally, the problem is the term "defined type" (and I am guilty as charged) which does not describe those types well. Originally, these types were called "named types" which also applied to the built-in types (since they have names). But when we introduced type aliases this didn't work well anymore because a type alias is clearly "named" yet it may (or may not be) a "defined type" (or a "named type" in the original sense). In retrospect, I believe the better term would have been "nominal type" which describes types whose properties are associated with their name rather than their structure. A type may be named (= have a name) and refer to a nominal or structural type. Built-in types and types declared by non-alias type declarations are nominal types. |
Yes, this issue is about the clarity of the spec. Thank you for improving the title! 👍 |
In my humble opinion,
So changing the name again might bring more confusion. Another solution could be just to state "Each predeclared type are a defined type if it's not a type alias" in the "Types" or "Predeclared identifiers" section. Then a reader will have to read 2 places to fully understand what the define type is , but it would be much better than the current situation. |
Change https://golang.org/cl/313309 mentions this issue: |
Situation
The spec says:
https://golang.org/ref/spec#Type_definitions
Also, whenever "defined type(s)" appears in the spec, it is linked to the definition above.
Problem
A reader may wrongly think that all defined types are created by type definition. But this is not true, because types such as
bool
,int
, andstring
are defined types that are not created by type definition.And if a reader wants to fully understand what defined types are, the reader has to read all sections below.
The problem is that the definition of "defined types" is not contained in one place of the spec.
Proposal
Adding a section or a paragraph just for the definition of "defined types" would help readers to understand the concept correctly and easily.
I would suggest adding a section "Defined types" before the section "Type identity" so that the new section belongs to Properties of types and values and Type identity section can naturally refer to "defined types".
The new section should look like this. I don't think this is good enough, but I just wanted to show my idea clearly.
Also, I suggest
to reduce the misunderstanding that "the new type" is the definition of "a defined type".
The text was updated successfully, but these errors were encountered: