Go 1.18
171–180 of 614 posts
Re: Go 1.18
#172Now time to update interface{} usage and shift to any . $ gofmt -r 'interface{} -> any' -l **/*.go Replace -l with -w to write.
Re: Go 1.18
#173I hope open source Go code in the wild remains easy to read and understand. Generics look cool, despite this possible downside.
I have already started having trouble understanding open source code using generics. I can see the upsides of having generics, but have lost the enthusiasm with which I used to browse Go code. I am still a junior engineer, so maybe it will get better with time.
Re: Go 1.18
#174Re: Go 1.18
#175Please keep in mind that generics are a pretty big hammer - they can add a lot of complication if not used with caution. Only use a language feature if you absolutely must.
Re: Go 1.18
#176In celebration of generics release, I was playing around with supporting Optionals via generics. If anyone's interested I am happy to make this a real project https://github.com/frenchie4111/go-generic-optional
type Optional[T any] struct {
value *T
}
Don't use a pointer - it's bad for performance. func MakeOptional[T any](value *T) Optional[T] {
Use `New` instead - it's the idiomatic name for a constructor in Go. Drop the `Optional` part - the module name suffices - the caller will see: `opt.New`. Personally I just call the module `optional`, I think it's clearer: `optional.New`. func (o* Optional[T]) Unwrap() (T, error) {
1. `Unwrap` reminds me of Rust's .Unwrap, which panics. Seems confusing.2. There's no error here, the situation is equivalent to a missing key in a map - it's enough to return a bool.
Here's my implementation so far: https://gist.github.com/Mawr-BF2/0a60da26f66b82ee87b98b03336.... Only thing I'm not sure about is whether the JSON serialization methods are necessary.
Re: Go 1.18
#177Re: Go 1.18
#178My favorite feature is a tiny, couple line bug fix that I pushed hard to get included during the feature freeze. Full details here, but a summary is below: https://github.com/golang/go/issues/51127 For the past ~8 years, many hundreds of people reported on GitHub - and likely many multiples more have encountered and not reported - a program that didn't work with the error "cannot unmarshal DNS..." This error seems to…
Although the "your best bet to get a desired change through isn't via a private call with a maintainer." comment directed at you made me chuckle.
Re: Go 1.18
#179Re: Go 1.18
#180Great to see this! Generics will drastically improve datastructure libraries. That said, for people worrying about overcomplication, fortunately methods can't have type parameters. That means ergonomic monads are not possible to implement, and we'll most probably not see the whole functional story play out in Go.
Also, type parameters were supposed to be included, but were dropped because it made the implementation more complex.