News for hackers. Stuff that matters.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by titzer on Thursday July 13, 2023 @10:50AM (#36710084)
> Checked exceptions are exactly analogous of Result/Either types.

No, they aren't.

They are not compositional. You may want to write `f(g())` but there's no way to write the parameter type of `f` to make this work (in Java). That's because checked exceptions are an "effect" that would require extending the Java type system.

Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by kaba0 on Thursday July 13, 2023 @10:57AM (#36710208)
Read my last paragraph.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by the_gipsy on Thursday July 13, 2023 @11:58AM (#36711342)
So they are better... in a theoretical implementation.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by int_19h on Thursday July 13, 2023 @10:41PM (#36718818)
A prototype of the Java compiler with composable checked exceptions existed at one point, so we know it's definitely doable.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by rcme on Thursday July 13, 2023 @07:11PM (#36717347)
How would you define f in a different language such that f(g()) worked? You couldn’t do that in Go, for instance.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by titzer on Thursday July 13, 2023 @07:45PM (#36717602)
There's at least one language, Koka (https://koka-lang.github.io/koka/doc/book.html) that has effects in its type system. There are probably others. If you don't have effects, you could use union types.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by rogerkeays on Friday July 14, 2023 @04:14AM (#36720842)
This language looks really cool. Thanks for sharing.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by clhodapp on Thursday July 13, 2023 @08:16PM (#36717845)
Simple! You just make f take in g's result type.
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by rogerkeays on Friday July 14, 2023 @12:10AM (#36719394)
... not sure if serious or not
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by clhodapp on Friday July 14, 2023 @12:14AM (#36719413)
I'm completely serious in the sense that you could do that and really would in some situations.

You might do it because you want to factor the handling of the different result cases out to another function.

Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by rogerkeays on Friday July 14, 2023 @04:17AM (#36720866)
You don't think it would limit the independent use of f()?
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by masklinn on Friday July 14, 2023 @10:44AM (#36724723)
No? Surely if f() takes a full result (including error condition) it's because there's something it wants to do with that?
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by EspressoGPT on Friday July 14, 2023 @02:20AM (#36720129)
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by hedora on Thursday July 13, 2023 @09:44PM (#36718451)
In rust, you write "f(g()?)", and make sure that your function body returns a Result<> with an error type that g()'s error type can be converted to.

It works great. Also, note that f() doesn't care about the type of error returned by g(), and that it will be a compilation error if g()'s error type turns into something incompatible.

Sadly, there are proposals to add exceptions to rust, and it seems likely they will be accepted, breaking error handling semantics across the entire ecosystem (even in new code, since exceptions are too hard to use correctly).

Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by rcme on Thursday July 13, 2023 @10:04PM (#36718582)
What's the rationale behind adding exceptions?
Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by emi2k01 on Thursday July 13, 2023 @10:47PM (#36718861)
I'm not sure what they mean by adding exceptions.

AFAIK, the only proposal related to exceptions is adding a `try` block that would scope the `?` operator to that block instead of the current function.

Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by masklinn on Friday July 14, 2023 @01:08AM (#36719704)
You could actually, iirc if f takes as many parameters as g returns it works out.

In a better langage f would take a Result, and then it can manipulate that however it wants.

Obviously you can also plug in adapters if you need some other composition e.g. g().map(f), g().and_then(f), …

Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by EspressoGPT on Friday July 14, 2023 @02:19AM (#36720116)
> You couldn’t do that in Go, for instance.

You can – by making f accept g's return types, including the error. This is even being done in the Go standard library: https://pkg.go.dev/text/template#Must

Re:Unchecked Java: Say Goodbye to Checked Exceptions Forever by rcme on Friday July 14, 2023 @08:48AM (#36723181)
That’s interesting, but consider two functions like func ParseInt(string) (int, error) and func Abs(int) int. You lose some composability when using errors over exceptions. The Rust solution mentioned elsewhere seems elegant.