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

spec: consolidate the definition of "defined types" #45587

Open
nobishino opened this issue Apr 15, 2021 · 5 comments
Open

spec: consolidate the definition of "defined types" #45587

nobishino opened this issue Apr 15, 2021 · 5 comments
Assignees
Milestone

Comments

@nobishino
Copy link
Contributor

@nobishino nobishino commented Apr 15, 2021

Situation

The spec says:

A type definition creates a new, distinct type with the same underlying type and operations as the given type, and binds an identifier to it.

TypeDef = identifier Type .

The new type is called a defined type. It is different from any other type, including the type it is created from.

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, and string 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.

## Defined types

A type is a defined type if and only if one of the following conditions applies:

- The type is created by type definition.
- The type is the predeclared `bool` type.
- The type is a predeclared numeric type such as `int` or `float64`.
- The type is the predeclared `string` type.

Also, I suggest

- The new type is called a defined type.
+ The new type is a defined type.

to reduce the misunderstanding that "the new type" is the definition of "a defined type".

@mknyszek mknyszek changed the title spec: The definition of "defined types" should be in one place spec: consolidate the definition of "defined types" Apr 15, 2021
@mknyszek mknyszek added this to the Backlog milestone Apr 15, 2021
@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Apr 15, 2021

As far as I can tell, this seems to be more about clarity and cleanup than proposing something new. Is that right?

CC @griesemer @ianlancetaylor @rsc

@griesemer griesemer self-assigned this Apr 15, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented Apr 15, 2021

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.

@nobishino
Copy link
Contributor Author

@nobishino nobishino commented Apr 15, 2021

As far as I can tell, this seems to be more about clarity and cleanup than proposing something new. Is that right?

Yes, this issue is about the clarity of the spec. Thank you for improving the title! 👍

@DQNEO
Copy link
Contributor

@DQNEO DQNEO commented Apr 16, 2021

In my humble opinion,

  • "nominal" sounds like it includes type alias , as alias is what binds an identifier to the given type.
  • People are already used to the term "defined type".

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.

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 24, 2021

Change https://golang.org/cl/313309 mentions this issue: spec: consolidate the definition of "defined types"

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

Successfully merging a pull request may close this issue.

None yet
5 participants