Guillermo Calvo 🐵

1.7K posts

Guillermo Calvo 🐵 banner
Guillermo Calvo 🐵

Guillermo Calvo 🐵

@gcalvo

🥔 I am a potato with arms sitting in front of a keyboard pressing buttons and hoping it works. @[email protected]

127.0.0.1 Katılım Ocak 2009
1.1K Takip Edilen222 Takipçiler
Ivan Abad
Ivan Abad@NetMentorTW·
Por lo visto mastercard dublin ha puesto sensores de peso en los escritorios de la gente para saber quien va a la oficina, quien va mucho a la cafetería, etc. Surrealista.
Español
3
0
3
587
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
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.
Guillermo Calvo 🐵@gcalvo

@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. quick-bench.com/q/IJ37DFk4x147…

English
0
0
0
68
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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. quick-bench.com/q/IJ37DFk4x147…
English
0
0
0
87
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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.
English
1
0
0
35
CedarDB
CedarDB@cedar_db·
Why old-school exceptions are still a good idea: They provide a better user and developer experience and are even faster than error values! Read more in our blog: cedardb.com/blog/exception…
English
1
6
51
3.9K
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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. #results-based-on-callables" target="_blank" rel="nofollow noopener">result.leakyabstractions.com/docs/start/cre…
English
1
0
1
36
Petromir Dzhunev
Petromir Dzhunev@dzhunev·
@gcalvo Great library and documentation. One thing I couldn't find is how to handle the case where I'm calling a third-party library that throws an exception
English
1
0
1
35
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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.
English
0
0
0
24
ʀᴏʙᴇʀᴛ ᴡɪɴᴋʟᴇʀ
@gcalvo @ilopmar What's the main advantage in your opinion of using a plain object type than using a runtimeexception object, which contains additional data, to represent an error in Result/Either?
English
2
0
0
41
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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.
English
2
0
1
40
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@rbrtwnklr @ilopmar I haven't used Vavr.io 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.
English
1
0
0
60
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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.
English
0
0
0
18
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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.
English
0
0
1
77
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@donal_tweets Hot take: I would even argue that exceptions in general don't exactly fit into the object-oriented paradigm.
English
0
0
0
30
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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.
English
0
0
0
5
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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`).
English
0
0
0
4
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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.
English
0
0
0
23
Guillermo Calvo 🐵
Guillermo Calvo 🐵@gcalvo·
@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.
English
1
0
0
24
Guillermo Calvo 🐵 retweetledi
Matthew Moss
Matthew Moss@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 advance for support and connections! linkedin.com/in/matthewdavi…
English
1
3
8
656