Ball is in your court now typescript-on-the-serverside ppl!
Go Replaces Interface{} with 'Any'
31–40 of 481 posts
Re: Go Replaces Interface{} with 'Any'
#32 []interface{}{1, 2.0, "hi"} -> []any{1, 2.0, "hi"}
Now that Go is going to have generics, all we need is sugar syntax for early return on error -- like more modern languages such as Rust and Zig have -- and Go may finally be pleasant to program in!Re: Go Replaces Interface{} with 'Any'
#33Loading this commit in safari almost killed my phone
Same for an old Android phone with outdated Snapdragon 660 I use to test app performance bottlenecks. Except this one took 4 secs to load.
Re: Go Replaces Interface{} with 'Any'
#34Ball is in your court now typescript-on-the-serverside ppl!
Also, application servers are cheap, persistent, fast and durable storage isn't, these won't be written in TS.
TL;DR: different problem domains, not important
Re: Go Replaces Interface{} with 'Any'
#35Earlier quoted context omitted.
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{}
Re: Go Replaces Interface{} with 'Any'
#36Re: Go Replaces Interface{} with 'Any'
#37Re: Go Replaces Interface{} with 'Any'
#38I 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'
#39Earlier quoted context omitted.
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.
It's much much more useful to the users to say, 2.0 introduced generics, it's distinct. If it's like other languages, generics changes the code people generate a lot, libraries start looking significantly different. It's very distinct, and if that is simply in version 1.18.0 or whatever, that is super bad usability from a language perspective.
Re: Go Replaces Interface{} with 'Any'
#40So 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?
While it's good to get up-to-date, I don't think anyone should go re-write code or radically change their programming style to use generics. There's no need to over-complicate things. Anywhere that you're either copy-pasting a bunch, or using code generation might be a good fit for generics.