3 ms·
Love this. Nothing better than coming to a go codebase and bumping the go version knowing everything will work fine. One thing I worry about is that the type s
by parhamn 3y ago
Love this. Nothing better than coming to a go codebase and bumping the go version knowing everything will work fine.
One thing I worry about is that the type system can’t get improved significantly without breaking changes in the “this was wrong and wont compile now" sense. Although I'm not sure theres interest for this stuff in the golang team at all. But there are many low hanging type system improvements in go that are major compile time robustness wins for folks, with no language additions.
1) reporting unchecked nils, might require formalizing [T, nil] | [nil, err] so err != nil guarantees T (obviously concurrent pointer access makes it tricky but thats special code with special considerations, not the 99% case)
2) unchecked array access
3) inferring types of nested struct literals. Writing nested GRPC calls is such a damn pain go, this is literally only one layer of type inference... its in the damn function signature I'm calling!
4) Exhaustive enum matches
But now I'm curious, is there any interest for these changes in the golang community? None are adding "features" (like say generics) but would be huge robustness wins and seem pretty easy.
- josephg 3y agoJust to beat this drum from outside the go community, rust / swift style enums with parameters are mana from heaven. So many programs get easier to write using them. If there’s one way I’d love the go type system to be improved, it would be by adding these simple, lovely algebraic data types. Trust me, they would look great in Go. Treat yourself.
- sharno 3y agoIt's ridiculous to me that the most popular languages from the last 20 years or more are the ones that handicapped. They have `and` types but not `or`. It sounds like a very basic logic tool that's needed for types.
- andyferris 3y agoI agree. If go had sum types I’d use it in a heartbeat!
- valzam 3y agoThe irony is that Go actually does have sum types, but only for generics! type A interface { Foo | Bar | Baz } Can't use this anywhere but in generic type signatures though :(
- bheadmaster 3y agoThere's a proposal [0] by Ian Lance Taylor that proposes extending the type parameter constrains union of types to non-generic interfaces too. Indeed, there are some issues with the implementation details, but I'm hoping they get ironed out. [0] https://github.com/golang/go/issues/57644 https://github.com/golang/go/issues/57644
- nickpeterson 3y agoGrumbles in F#…
- deleted 3y ago[deleted]