I'm excited to share my side project: Result is an #OpenSource library for #Java to handle success & failure without #exceptions. π According to benchmarks, it's 150x faster than traditional exception handling! β‘ Check it out and share your feedback! π
https://t.co/zQoW8wool7
I came across a post about #ExceptionHandling via a video by ThePrimeagen. While I enjoyed the article, I disagreed with the claim that exceptions are more performant than error values. So I examined the provided benchmarks and noticed something that might be worth a closer look.
@cedar_db When you factor in the non-happy path, `fib_throws` could be significantly slower than `fib_expected` -- possibly by an order of magnitude. So overall, I don't think the performance argument clearly favors exceptions over error values.
https://t.co/7OeEpBYydJ
@cedar_db When you factor in the non-happy path, `fib_throws` could be significantly slower than `fib_expected` -- possibly by an order of magnitude. So overall, I don't think the performance argument clearly favors exceptions over error values.
https://t.co/7OeEpBYydJ
@cedar_db Great post! Looking into the C++ benchmarks though, I noticed that `do_fib_expected` unnecessarily unwraps and re-wraps errors, whereas `do_fib_throws` simply propagates exceptions upstream. Most importantly, the benchmarks only focus on the happy path.
@dzhunev Thank you! That use case is covered by `Results.ofCallable`. It encapsulates the exception as a failed result, so you don't have to `catch` it manually.
https://t.co/8uXVaCgYJk
I'm excited to share my side project: Result is an #OpenSource library for #Java to handle success & failure without #exceptions. π According to benchmarks, it's 150x faster than traditional exception handling! β‘ Check it out and share your feedback! π
https://t.co/zQoW8wool7
@rbrtwnklr@ilopmar Sometimes, the set of errors a method can fail with can be represented as a simple enum. Java records are great for encapsulating a few details too. IMO these approaches are simpler and more straightforward than using exceptions, especially when you don't plan to throw them.
@rbrtwnklr@ilopmar On the other hand, `Try` is more similar to `Result` semantically, but it restricts the representation of "failures" to instances of `Exception`. In my experience, I've found it way more convenient to express failures with any object type, not just exceptions.
@rbrtwnklr@ilopmar I haven't used https://t.co/qxhQV3QGsc personally (but I think it's a cool project). As far as I can tell, `Either` is a generic "left or right" container. So, it's more abstract than a `Result`, which is specifically designed for error handling.
@donal_tweets You won't believe this, but I would rather use monadic containers for signaling errors. π€ I wonder if anyone has ever thought of developing a library for that. Oh, wait.
@saw303 Not really. I was scratching an itch I wasn't sure anyone else had. I modeled it after Optional to make it easier to use. Then I found out about Rust's Result type, which made me think I could be on the right track. Rust's question mark operator looks very convenient, by the way.
@donal_tweets Among other pain points, checked exceptions simply don't play nice with functional programming. This library tries to provide a functional error-handling approach as an alternative to checked exceptions.
@donal_tweets Exactly. A Result is just a container for either "an error or a value".
You're right about not being able to "unwrap" the value without considering the possibility of error; the point of Results is that you don't *need to* unwrap the value to manipulate it (think of `Stream`).
@donal_tweets Exception-throwing methods have even more inconvenient implications. For example, you can't possibly use your version of `getServerUptime` as a `Supplier`. One of the goals of this library is to make functional programming easier in Java.
@donal_tweets If `ConnectionException` is checked (which is kind of implied in the example), someone else will have to `try` and `catch` it. The new version of the method is simply kicking the can down the road. It will make someone else's code uglier.
Today was my last day after 10 years with a great company and co-workers. I'm looking for a new opportunity! Thanks in advance for support and connections!
https://t.co/u6juTfJnwg