Live data from Hacker News

Go Replaces Interface{} with 'Any'

github.com

71–80 of 481 posts

Re: Go Replaces Interface{} with 'Any'

#71
post #36

Earlier quoted context omitted.

I’m not a typescript person, but to be fair to typescript, its type system is still much more expressive than Go’s, even with the generics addition

Typescript is stricter and safer while also being less obtrusive than Go

Any language based on JS can't be safer than Go. The end result of TS is JS which is a dynamic language.

Re: Go Replaces Interface{} with 'Any'

#72
post #65

Their code is full of things like: type fileOps []any // []T where T is (string | int64) Go does not have neither generics nor union types. So people have to do this kind of thing :( I feel sorry for them. Reminds of Java 4 (15 years ago or something) where code was full of this crap: List /* */ values; Map /* */ map; Some devs spent a whole week doing nothing other than removing those commented out generic type decl…

You could have sum types, and not generics to cover many of these cases I guess? And then Go could have the error type it kind of wants to have.

Re: Go Replaces Interface{} with 'Any'

#73
post #65

Their code is full of things like: type fileOps []any // []T where T is (string | int64) Go does not have neither generics nor union types. So people have to do this kind of thing :( I feel sorry for them. Reminds of Java 4 (15 years ago or something) where code was full of this crap: List /* */ values; Map /* */ map; Some devs spent a whole week doing nothing other than removing those commented out generic type decl…

> Some devs spent a whole week doing nothing other than removing those commented out generic type declarations once Java finally got generics!

Fast-forwarding to today, could Co-pilot have saved them the trouble?

Re: Go Replaces Interface{} with 'Any'

#74
post #39

Earlier quoted context omitted.

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.

Sure, but semantic versioning really is the wrong kind of versioning to use for a language. The major version should represent major language changes, not whether its a breaking change or not, semantic versioning isn't somehow magically a "good" way to version. It's useful for libraries / dependencies where you are dealing with many different libraries and just want to know you can upgrade without having to deal with…

> The major version should represent major language changes, not whether its a breaking change or not

Why?

Old code still work and unless you are purposefully maintaining an old system you are expected to use the last version anyway. What does it actually change that generics were introduced in version 1.18 rather than 2.0? From now on, Go has generics. As there is no breaking change, it’s not like you had to keep using the previous version to opt out.

Re: Go Replaces Interface{} with 'Any'

#75
post #73
post #65

Their code is full of things like: type fileOps []any // []T where T is (string | int64) Go does not have neither generics nor union types. So people have to do this kind of thing :( I feel sorry for them. Reminds of Java 4 (15 years ago or something) where code was full of this crap: List /* */ values; Map /* */ map; Some devs spent a whole week doing nothing other than removing those commented out generic type decl…

> Some devs spent a whole week doing nothing other than removing those commented out generic type declarations once Java finally got generics! Fast-forwarding to today, could Co-pilot have saved them the trouble?

I'm pretty sure sed could have saved them the trouble.

Re: Go Replaces Interface{} with 'Any'

#76
post #65

Their code is full of things like: type fileOps []any // []T where T is (string | int64) Go does not have neither generics nor union types. So people have to do this kind of thing :( I feel sorry for them. Reminds of Java 4 (15 years ago or something) where code was full of this crap: List /* */ values; Map /* */ map; Some devs spent a whole week doing nothing other than removing those commented out generic type decl…

Go has generics in that commit.

Re: Go Replaces Interface{} with 'Any'

#77
post #65

Their code is full of things like: type fileOps []any // []T where T is (string | int64) Go does not have neither generics nor union types. So people have to do this kind of thing :( I feel sorry for them. Reminds of Java 4 (15 years ago or something) where code was full of this crap: List /* */ values; Map /* */ map; Some devs spent a whole week doing nothing other than removing those commented out generic type decl…

1.18 Beta is out today with Generics

Re: Go Replaces Interface{} with 'Any'

#78
post #50
post #32

This is fantastic. It'll make Go feel much less weird. eg from the diff: []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!

I cannot wait for the Result monad. The state of error handling in Go at the moment is embarrassing at best.

People downvote it, but it's true. 2/3 of your Go code is `if err` blocks. And the way you have to chain the error messages to make the stack make any kind of sense is just maddening.

Re: Go Replaces Interface{} with 'Any'

#79
post #50

Earlier quoted context omitted.

I cannot wait for the Result monad. The state of error handling in Go at the moment is embarrassing at best.

Emulating sum types in languages without pattern matching is extremely awkward, to the point of being almost useless. type Result[T] struct { ok: *T err: error } Great, so how do you work with it? * You can have a `ok()` getter that returns `*T`. Now you you need an `if x != nil` * `isOk()` + `isErr()` * `unwrap() T`, which panics on errors * `split() (*T, err)` that splits into separate values, especially awkward si…

> because eventually you have to do...

Emphasis on eventually instead of at every single function call.

Re: Go Replaces Interface{} with 'Any'

#80
post #65

Their code is full of things like: type fileOps []any // []T where T is (string | int64) Go does not have neither generics nor union types. So people have to do this kind of thing :( I feel sorry for them. Reminds of Java 4 (15 years ago or something) where code was full of this crap: List /* */ values; Map /* */ map; Some devs spent a whole week doing nothing other than removing those commented out generic type decl…

You're lucky: Go 1.18 Beta 1 was released today, which has generics.
Post reply on HN