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?
The advantage of pattern matching is that it is very flexible and powerful at the same time. Within the pattern, the data structure can be dynamically disassembled. These parts can then be assigned directly to variables that only apply within this expression.
It turned out that pattern matching in their example was significantly faster than if-else tests. Even though the code doesn't utilize any special pattern match cases that would not be possible with if-else tests, it just compares integers.
Pattern matching is used to determine whether source files of high-level languages are syntactically correct. It is also used to find and replace a matching pattern in a text or code with another text/code. Any application that supports search functionality uses pattern matching in one way or another.
Pattern Matching works by "reading" through text strings to match patterns that are defined using Pattern Matching Expressions, also known as Regular Expressions. Pattern Matching can be used in Identification as well as in Pre-Classification Processing, Page Processing, or Storage Processing.
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With