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 clarification on named vs. unnamed types #5682

Closed
btracey opened this issue Jun 11, 2013 · 6 comments
Closed

Spec clarification on named vs. unnamed types #5682

btracey opened this issue Jun 11, 2013 · 6 comments

Comments

@btracey
Copy link
Contributor

btracey commented Jun 11, 2013

There has been some confusion over the meaning of named vs. unnamed types. I for one was
confused about "float64" being a named type, and upon learning that, was
confused about what unnamed types are. It's obvious that anything to which a programmer
gives a name is a named type, but I don't think it's obvious that the predefined types
are named types.

The only place I see in the spec that talks about it is the following line:

"Named instances of the boolean, numeric, and string types are predeclared.
Composite types—array, struct, pointer, function, interface, slice, map, and channel
types—may be constructed using type literals."

With careful reading, this does say that float64 is a named type, but I think it could
be improved by saying something like "All of the predeclared boolean, numeric and
string types are named types." There is no confusion if a "named
instance" is the same as a "named type", and has a side bonus of someone
doing a find for "named type" would now easily find this line.

Secondly, this definition says nothing explicit about what an unnamed type is. It would
be nice if this was changed to explicitly state what are unnamed types.

While on the one hand I can see the argument "clearly []string is not a named type,
no one gave it a name", at the same time no Go programmer gave float64 a name
either. To me at least, the fact that

type Myfloat float64

is not assignable to a float64, while 

type Myfloatslice []float64

is assignable to a []float64 is surprising, and I would appreciate further clarification
in the spec.
@robpike
Copy link
Contributor

robpike commented Jun 12, 2013

Comment 1:

They have a name, so they're named types. What's hard to understand? T is a named type,
*T is not a named type, type PT *T creates the named type PT.
There's a tautology here: a named type is a type with a name. Perhaps it could be
explained better but it's like defining what "is" is.

@btracey
Copy link
Contributor Author

btracey commented Jun 12, 2013

Comment 2:

It's not hard to understand, it's just that there are a number of things it could mean
in the grand scheme of things a person could call a named type. "Of course float64 isn't
a named type, did you give it a name?" or "Of course []float64 has a name, it's a slice
of floats". Even making the statement "a named type is a type with a name" is better
than what's currently there as it defines a named type as a type which has a name rather
than a type which was given a name

@cznic
Copy link
Contributor

cznic commented Jun 12, 2013

Comment 3:

@2: What about: "A named type is a type which can be referred to using a valid Go
identifier"? 
- b/c that's the essence of what are named types for.
- b/c type literals (aka unnamed/anonymous types) can never be valid Go identifiers.

@btracey
Copy link
Contributor Author

btracey commented Jun 12, 2013

Comment 4:

I like that a lot.

@griesemer
Copy link
Contributor

Comment 5:

https://golang.org/cl/11055043

Owner changed to @griesemer.

Status changed to Accepted.

@griesemer
Copy link
Contributor

Comment 6:

This issue was closed by revision 8268ead.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants