Here are my notes from [Olivier Hervieu's talk in RuPy 2013 about the handling of errors.
- Shit happens. It's so common that a unicode character exists for it. But don't let it hit the fan.
- Disasters in programs: Death, destruction, floating point exceptions.
To err is human, to persist in error is diabolical.
Humans make errors, software made by humans has errors. But we want error-proof software.
Three ways to manage software: Return code, an exception, or monadic error control. Every language has at least 2 of them.
C has no exceptions, errors handled by return code or the errno special register.
Return codes are easy to implement, but can be easily ignored. Not universal, need to be translated. Rely on conventions. Safely managing all of them is painful.
Errno should be reset manually. Safely using it is very hard.
Some methods may return a status which isn't really an error, but just a status.
Exceptions are great when everything goes wrong. Sadly don't cross process boundaries. In some languages you have to clean up memory too.
In Go, there were initially no exceptions. Return codes within method signatures. You need to declare a variable to handle the error. Now Go implements exceptions using carefully chosen keywords (
Dynamic languages, particularly Python, love exceptions. End of iteration is an exception (but not end of file). Programmers abuse this features.
Exceptions allow function composition.
Java Exceptions give you a way to know which Exceptions may be thrown, but they are not widely used.
socket.sendreturns the number of bytes sent. You always have to check it. Based on Ohloh, there's a lot of code that does not check it.
Monadic error handling: Haskell Maybe and Either monads. Easy composition. Can preserve errors without throwing exceptions and halting the computation.
Rules of thumb: Exceptions for unexpected failures. If a method potentially returns an error, use an error code. If you need function composition, use monadic error control.
In your library, be consistent!
Know Your AngularJS Inside Out
Build Your Own AngularJS helps you understand everything there is to understand about AngularJS (1.x). By creating your very own implementation of AngularJS piece by piece, you gain deep insight into what makes this framework tick. Say goodbye to fixing problems by trial and error and hello to reasoning your way through them
- RuPy 2013: OpenStack Development: How We Build It And ow You Can Help
- RuPy 2013: Dealing With Complexity