Earlier quoted context omitted.
A lot of people are going to write very un-idiomatic Go code with "Result" types built on simple generics that, 5 years from now, we'll all be kind of smirking at. Rust's Option and Result make sense because the language supports it (most importantly with match statements). They don't make sense here.
Fun observation of mine: most articles/tutorials I've read about "idiomatic go code" are presenting ideas that you never see in any production code. Seems to me that the ones who write about "idiomatic go code" aren't the ones who are shipping softwares/libraries.
Go Replaces Interface{} with 'Any'
171–180 of 481 posts
Re: Go Replaces Interface{} with 'Any'
#172Earlier quoted context omitted.
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…
Get your point, but I kind of like it. It tells some really important info, and they are hardly alone. Python 3.x was breaking change. Until they they stayed in 2.x versioning a long time. And we will never see a Python 4.x
Re: Go Replaces Interface{} with 'Any'
#173Earlier quoted context omitted.
Go exceptions do carry stack trace information. However, the topic is errors, not exceptions. Those are very different concepts. Of what use is stack trace information in debugging values that you have assigned error meaning to when not other types of values? If you had a function func add(a, b int) int { return a * b } there would be no expectation of carrying a stack trace to debug it. So what's different about fun…
Current state of the art: func read_file(filename string) (string, error) { return "", errors.New("oops") } func foo() error { a, err := read_file("a.txt") if err != nil { return errors.New(fmt.Sprintf("read a: %s", err)) } b, err := read_file("b.txt") if err != nil { return errors.New(fmt.Sprintf("read b: %s", err)) } // do stuff with a and b return nil } func main() { err := foo() if err != nil { fmt.Fprintln(os.St…
Re: Go Replaces Interface{} with 'Any'
#174Earlier quoted context omitted.
> It implies that the expected behavior is the "happy path" (everything went well) and any deviations (errors) is unexpected. Errors are the "happy path", though. Your network connection was lost for the data you were trying to transmit so you saved it to your hard drive instead means that everything went well! Throwing your hands up in the air and crashing your program because you had to make a decision is not somet…
> Throwing your hands up in the air and crashing your program because you had to make a decision is not something you would normally want to do And that's not something you do thanks to try/catch. You just handle the error where it's meaningful to handle it. The happy path of "make a request" is that there is no network error. The happy path of "make sure this request is sent" is that you handle the unexpected networ…
It is very weird that this subthread starts with "current state of the art".
Re: Go Replaces Interface{} with 'Any'
#175Earlier quoted context omitted.
I don't see why that wouldn't be possible to implement now that the generics are here.
Which is exactly why I said: > I cannot wait for the Result monad. Generics make this possible, and will be a huge improvement to Go's error handling. I'm not saying it will solve everything, but it's a huge step nonetheless.
Convenience is not a goal of the language, generally.
Re: Go Replaces Interface{} with 'Any'
#176This 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!
It's definitely more streamlined, but my concern would be that newcomers might not understand that it's just an alias. Learning Go really reframed my concept of what an interface is, and I thought that using an empty interface to represent "any type" was kind of ingenious, and helps reinforce its ethos. An empty interface can represent any type because every type inherently implements an interface with no methods. An…
Re: Go Replaces Interface{} with 'Any'
#177I'd really like it if Github handled massive commits like this one better. The way they present it is not very pleasant to navigate.
Re: Go Replaces Interface{} with 'Any'
#178Like it! Now, can they continue to add more “useless” improvements like while-loops and so on.
https://go.dev/tour/flowcontrol/3 for sum < 1000 { sum += sum }
while sum
reads better (like English).Re: Go Replaces Interface{} with 'Any'
#179Boy, I still remember when I go shit on by Real Go Devs who insisted there was never a need for more than one GOPATH or real dep management. And raged when I gave countless examples of how large Go projects (cough k8s) were doing all sorts of ... creative stuff... to accomodate The Google Way.
Re: Go Replaces Interface{} with 'Any'
#180Earlier quoted context omitted.
Well it's better than most language with exceptions. People makes it a big deal, in reality it's not.
An exception has a stacktrace. This single piece of information is crucial when you debug and makes handling errors in Golang embarrassing. I rest my case.