![Guillermo Calvo π΅ Profile](https://pbs.twimg.com/profile_images/749533895788490756/-ktIZaLU_x96.jpg)
Guillermo Calvo π΅
@gcalvo
Followers
227
Following
6K
Statuses
2K
π₯ I am a potato with arms sitting in front of a keyboard pressing buttons and hoping it works. @[email protected]
127.0.0.1
Joined January 2009
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! π
4
12
30
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.
0
0
0
@rbrtwnklr @ilopmar Yes, that's the sad part about throwing runtime exceptions. They are very easily ignored.
0
0
0
@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.
0
0
0
@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.
2
0
1
@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.
0
0
0
@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.
0
0
1
@donal_tweets Hot take: I would even argue that exceptions in general don't exactly fit into the object-oriented paradigm.
0
0
0
@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.
0
0
0
@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`).
0
0
0
@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.
0
0
0
RT @mattdmoss: Today was my last day after 10 years with a great company and co-workers. I'm looking for a new opportunity! Thanks in advanβ¦
0
3
0
RT @puneetbhl: π Currently on the hunt for new career opportunities! π Seeking roles in Software Engineering. Any leads or connections woulβ¦
0
9
0