News for hackers. Stuff that matters.
Re:Error stack traces in Go with x/xerror by andrenth on Monday August 23, 2021 @08:31PM (#28283819)
> That enforced error handling is novel to Rust afaik

Hardly, though Rust of course has merit in making it popular, to the point that people think it was introduced by the language.

Re:Error stack traces in Go with x/xerror by OJFord on Monday August 23, 2021 @08:48PM (#28283912)
Well that's why I said as far as I know. What else has something similar?
Re:Error stack traces in Go with x/xerror by monocasa on Monday August 23, 2021 @09:10PM (#28284050)
Anything with ADTs. I know it from the ML family of languages (Ocaml, Standard ML, F#, etc.)
Re:Error stack traces in Go with x/xerror by Zababa on Tuesday August 24, 2021 @03:46AM (#28286068)
I think one difference between Rust and OCaml is that in Rust non exhaustive pattern matches are an error, while in OCaml they are a warning.
Re:Error stack traces in Go with x/xerror by OJFord on Monday August 23, 2021 @09:18PM (#28284085)
> Anything with ADTs.

Well that's not true, that's completely orthogonal?

Re:Error stack traces in Go with x/xerror by monocasa on Monday August 23, 2021 @10:29PM (#28284508)
It's not. "Forced error handling" in Rust (particularly when contrasted with something like Go like we're doing here) is exemplified with the Option and Result types, and how the compiler will maintain type safety around the concepts of success and error. ADTs are what lets it do that, and the MLs do that as well. You can also see this in how Typescript for example uses ADTs for typesafe error/success state space enumeration.
Re:Error stack traces in Go with x/xerror by OJFord on Tuesday August 24, 2021 @04:46AM (#28286389)
But you could have ADTs without using them for 'forced error handling', and you could have 'forced error handling' without using ADTs for it - C could require 'consumption' (for a slightly less strict meaning of it) of return values. That's the bit I think is interesting/was new to me. You can't just call `maybe_works();`, you have to explicitly consume its 'result', even if just to propagate the error as `maybe_works()?;`.
Re:Error stack traces in Go with x/xerror by monocasa on Tuesday August 24, 2021 @11:03AM (#28289765)
Oh, ok. Yeah that in fact does exist in C and C++ the same way as in Rust. Rust doesn't actually by default require you to consume a return value; a lot of functions are just marked as #[must_use]. C and C++ do the same thing with [[nodiscard]] and __attribute__((warn_unused_result)).

There's a go vet pass as well. https://pkg.go.dev/github.com/golangci/govet#hdr-Unused_resu...

Re:Error stack traces in Go with x/xerror by ttymck on Monday August 23, 2021 @10:35PM (#28284552)
No, not really, it's an accurate summation of where the pattern is commonly found. ADTs, like Rust's Enum, enable this kind of error handling, and are made more ergonomic with monad behaviors.

Scala's Either[A, B] is another example.

Re:Error stack traces in Go with x/xerror by scns on Tuesday August 24, 2021 @02:58AM (#28285858)
Yes, but Haskells'/Scalas' Either is abstract while Rusts' Result is specific SFBAP (Sorry For Being A Pedant).
Re:Error stack traces in Go with x/xerror by ttymck on Tuesday August 24, 2021 @01:47PM (#28292446)
Can you clarify the distinction between "abstract" and "specific"?

Is Scala's Try[A] "specific"?

Re:Error stack traces in Go with x/xerror by scns on Wednesday August 25, 2021 @04:17PM (#28306380)
Sure. Result is specific, you get a value or an error. Either can be used the same way, but you don't have to. The convention is use Right for the value and Left for the error but you can use it in other ways too, eg Left for an Int and Right for a Float.
Re:Error stack traces in Go with x/xerror by content_sesh on Monday August 23, 2021 @08:54PM (#28283954)
Haskell's Maybe type (monad?) comes to mind.
Re:Error stack traces in Go with x/xerror by OJFord on Monday August 23, 2021 @09:22PM (#28284102)
That's true, it's a while since I did only a little bit of Haskell, but yes. I suppose I didn't think of it because it feels less like 'having to handle' it in Haskell, since that's the norm anyway.

Whereas if you compare Rust to Python, C(++), or Go as I was - having to consume a returned 'result' is more notable.