Now for better error handling

@mistersql

Now for better error handling

Self-replies

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 -.....

Batch 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!

Exceptions 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.

Exceptions 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.

Exception conflate categories of errors:
- recoverable errors, e.g. try again
- unrecoverable errors (panic!)

Because they're the same, recoverable errors are unnecessarily expensive.

Exceptions 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?

Everything 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?

Risk of Union types is the calling code ignores the Error, e.g. if return Tuple[Answer,Error]

You can do this style of error handling with `returns`

pypi.org/project/returns

`@safe` decorator will make a ordinary function return Results (unions of answer/error) . I think.

@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.

@safe Type checker now tells us if an exception ignored. Maybe. Not clear if mypy can handle this pattern/library.