When I'm programming in Erlang should I be validating all return values from function calls for success via pattern matching even if i don't intend to use the return value? Most Erlang APIs I've seen so far don't throw exceptions on error (but return something like {error, Error}) so I must need to validate the return value yes? Any exceptions to this where I don't really need to worry about it?
It's good programming style to crash as early as possible when something has gone wrong. Anything you execute after that will be done with the system in an unknown state.
Unless you intend to handle the error value and do something on it, you write your code for the successful case. As in the following little sad loop:
life() ->
ok = work(),
ok = rest(),
life().
Some background reading about "let it crash" vs. "defensive programming"
http://mazenharake.wordpress.com/2009/09/14/let-it-crash-the-right-way/
http://jeremy.marzhillstudios.com/index.php/site-news/error-handling-erlang-vs-other-languages/
http://debasishg.blogspot.com/2007/10/defensive-programming-what-is-that.html
http://groups.google.com/group/ceug/browse_frm/thread/03842971fde80062#
(I like the quote:
There are no unplanned messages :) Don't handle them.