#pyconus Now for better error handling
Composability is a good design goal. It needs to be effortless/seamless.
Impediments to this:
GOTO- Single entry/exit helps composibility
modulelack- i.e. code polluting the global namespace
inheritance- breaks encapsulation
error handling -.....♡ 0 ↻ 0Batch languages didn't need error handling. Either that batch succeeded or it failed. Only matters in realtime code.
Global error handlers created race conditions.
Some OSs tried to handle error handling on behalf of the app (app error handlers and "resumptions") - Crazy idea!♡ 1 ↻ 0Exceptions should be part of language not the OS. Domain concerns.
Standard way to report errors. Errors harder to ignore. App now has possibility to recover.♡ 0 ↻ 0Exceptions don't scale. They work poorly with the typesystem. (huh?)
Shadown type system in C++/java called "exception specifications" failed. (What? I don't know what these are) Deprecated in C++.
Okay I'll have to look that up.
♡ 0 ↻ 0Exception conflate categories of errors:
- recoverable errors, e.g. try again
- unrecoverable errors (panic!)Because they're the same, recoverable errors are unnecessarily expensive.
♡ 1 ↻ 0Exceptions destroy partial calculations (waste compute)
Maybe instead return a union of Error and the Answer.me: I hate coding against unions. Will we hear why suddenly Unions are good?
♡ 1 ↻ 0Everything returns a union or collection of unions and you use pattern matching for handling every result that could error-out. So maybe replace try/except/finally with switch statements?
♡ 0 ↻ 0Risk of Union types is the calling code ignores the Error, e.g. if return Tuple[Answer,Error]
♡ 0 ↻ 0You can do this style of error handling with `returns`
♡ 0 ↻ 0`@safe` decorator will make a ordinary function return Results (unions of answer/error) . I think.
♡ 0 ↻ 0@safe Use `bind` function to chain/compose many functions that all use these Union Result types.
`do` notation uses comprehension notation to chain/compose functions with multiple args. I think.
♡ 0 ↻ 0@safe Type checker now tells us if an exception ignored. Maybe. Not clear if mypy can handle this pattern/library.
♡ 0 ↻ 0@safe Rust, Kotlin, newer C++ already do this style of error handling.
I guess this is handy if you want to make sure no exception causes a crash w/o resorting to a global error handler
♡ 0 ↻ 0@safe This is the repo for the sample code from the talk
♡ 1 ↻ 0