3 ms·
The article states the following things about error handling: Implicit error handling > Simpler to get started, thus ideal for novice developers. Explicit error
by thornewolf 2y ago
The article states the following things about error handling:
Implicit error handling
> Simpler to get started, thus ideal for novice developers.
Explicit error handling
> More to learn & write, thus better suited to seasoned developers.
These two statements seem odd. I believe an equally valid argument is that explicit error handling, in its explicitness, makes it easier for novice developers, as they no longer need to model their library function's behavior in their head. However, I believe the most reasonable approach is opt-in explicit error handling.
To use the lingo in the article.
- Should function signatures contain errors? (opt-in, lean yes)
- Should call sites explicitly handle errors? (opt-in)
- Should libraries opt-in to function signatures with errors? (probably yes)
As a client, almost every time, I want my error to bubble. If any step in my golden path fails, with the exception of transient http calls, the entire flow is probably done for. Do my top level functions need to explicitly state their errors? Probably not. Do I want library functions to do this? Probably.
I think this context is important for developer experience. And since I believe this varies on context, I believe function signature errors should be opt-in.
- Yoric 2y agoI actually think that having both possibilities, as in the OP, is the most complex solution of all, especially if you need to go hunting for a `?` that could be anywhere on your screen.
- zupa-hu 2y agoThe problem is that making function signature errors optional effectively "colors" all the functions. If I want to write a function with errors in the signature, then what if I call a function that doesn't have the error in the signature? In the presence of dynamic dispatch (ie. interfaces), the compiler can't infer the errors. Thus errors in function signatures can be required or not, but they can not be optional. (Please point out any of my mistakes.)
- thornewolf 2y agoThis is a good callout. I don't have any disagreements but will have to think about this. Maybe my proposal is not reasonable for the reasons you provide.