Live data from Hacker News

Go Replaces Interface{} with 'Any'

github.com

1–10 of 481 posts

Re: Go Replaces Interface{} with 'Any'

#3

It's a type alias, introduced for generics. By the way, Go 1.18 Beta 1 is released (with generics): https://groups.google.com/g/golang-announce/c/eAjK4Oezs_A

How is generics not a big enough change to warrant 2.0?

Edit: I’m impressed generics aren’t a breaking change! I thought this changed Interface{} to Any as a breaking change

Re: Go Replaces Interface{} with 'Any'

#4
post #3

It's a type alias, introduced for generics. By the way, Go 1.18 Beta 1 is released (with generics): https://groups.google.com/g/golang-announce/c/eAjK4Oezs_A

How is generics not a big enough change to warrant 2.0? Edit: I’m impressed generics aren’t a breaking change! I thought this changed Interface{} to Any as a breaking change

It's not a breaking change.

Re: Go Replaces Interface{} with 'Any'

#5

It's a type alias, introduced for generics. By the way, Go 1.18 Beta 1 is released (with generics): https://groups.google.com/g/golang-announce/c/eAjK4Oezs_A

AFAICT, its usage is not restricted to generics. It seems to be suggested to use anywhere you would use interface{}.

For the release announcement: https://news.ycombinator.com/item?id=29556646

Re: Go Replaces Interface{} with 'Any'

#6
post #3

It's a type alias, introduced for generics. By the way, Go 1.18 Beta 1 is released (with generics): https://groups.google.com/g/golang-announce/c/eAjK4Oezs_A

How is generics not a big enough change to warrant 2.0? Edit: I’m impressed generics aren’t a breaking change! I thought this changed Interface{} to Any as a breaking change

They are backwards compatible and don't break people's code, so it's 1.x.

Re: Go Replaces Interface{} with 'Any'

#7
post #3

It's a type alias, introduced for generics. By the way, Go 1.18 Beta 1 is released (with generics): https://groups.google.com/g/golang-announce/c/eAjK4Oezs_A

How is generics not a big enough change to warrant 2.0? Edit: I’m impressed generics aren’t a breaking change! I thought this changed Interface{} to Any as a breaking change

In semantic versioning, going from 1.X to 2.X is only indicated when there are incompatible API changes. Adding generics doesn’t break compatibility with preexisting Go code, so it’s unnecessary to increment the major version.

Re: Go Replaces Interface{} with 'Any'

#8
post #5

It's a type alias, introduced for generics. By the way, Go 1.18 Beta 1 is released (with generics): https://groups.google.com/g/golang-announce/c/eAjK4Oezs_A

AFAICT, its usage is not restricted to generics. It seems to be suggested to use anywhere you would use interface{}. For the release announcement: https://news.ycombinator.com/item?id=29556646

Yes, it's not restricted to generics. But the reason the alias was introduced is generics. Because they use interfaces to specify bounds (constraints) for type parameters (bounded polymorphism): [T fmt.Stringer], [T io.Reader], ...

So an unbounded type parameter is [T interface{}], or [T any] when using the shorter alias. It's a type alias / predeclared identifier defined in the universe scope:

   type any = interface{}
Post reply on HN