Live data from Hacker News

Go Replaces Interface{} with 'Any'

github.com

11–20 of 481 posts

Re: Go Replaces Interface{} with 'Any'

#13
post #11

This is great, as much as interface{} is not great, it's still part of the language and really verbose/non-descriptive. I'm guessing any was a forbidden word?

> I'm guessing any was a forbidden word?

You mean a reserved keyword? No, 'any' is not a keyword, it's an identifier (a predeclared identifier). The usual shadowing rules apply.

Re: Go Replaces Interface{} with 'Any'

#14
post #9

I like it, interface{} always felt unlike anything else in go other than structs.

Why does 'interface{}' feel unlike 'interface{String() string}' to you? Just because it doesn't have a method? You know that you can inline non-empty interfaces, too?

    func foo(x interface{String() string}) string {
        return x.String()
    }

Re: Go Replaces Interface{} with 'Any'

#17
post #11

This is great, as much as interface{} is not great, it's still part of the language and really verbose/non-descriptive. I'm guessing any was a forbidden word?

It wasn't so much that `any` was forbidden as that `interface{}` practically meaning "any value" fell naturally out of Go's existing type system rules, so there was no need to introduce another concept.

But having `any` as syntactic sugar for that concept is a good idea.

Re: Go Replaces Interface{} with 'Any'

#18
post #16

So now that go has generics and modules, is there an up-to-date intro for writing cutting-edge Go code for people who are already pretty familiar with the older styles?

There is lots of tutorial-style documentation on modules: https://go.dev/doc/#developing-modules

There is also a tutorial on generics: https://go.dev/doc/tutorial/generics

Re: Go Replaces Interface{} with 'Any'

#19
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

See https://semver.org/ for more details. https://0ver.org/ is fairly popular, and I see https://calver.org/ pretty often too.

Re: Go Replaces Interface{} with 'Any'

#20
post #16

So now that go has generics and modules, is there an up-to-date intro for writing cutting-edge Go code for people who are already pretty familiar with the older styles?

There is lots of tutorial-style documentation on modules: https://go.dev/doc/#developing-modules There is also a tutorial on generics: https://go.dev/doc/tutorial/generics

I tried doing the modules tutorial a while back but had difficulty with the directory structure. At some point I think the "recommended" directory structure became mandatory and I don't think my personal dev environment ever quite lined-up with it. Perhaps I should wait another year then buy a book.
Post reply on HN