Monthly Read Posts in Aug 2018
Programming Languages
CppCon 2015: Fedor Pikus “The Unexceptional Exceptions”
Handling exceptions is just as to handle errors using error code, exception is just a tool.
The key point is to maintain the program state in a well defiend state.
Turn error handling into resource management and use RAII to automate it; use explicit try…catch only when absolute necessary.
Bonus tip: avoid uses of pthread_cancel
.
Pros and cons of functional programming
Pure function: avoid shared state; immutable structures; function composition.
Declarative: instead of answers the question ‘how to do’ in imperative style, it answers the question ‘what to do’; imperative relies on instructions while declarative relies more on expressions.
Cons of FP: not suitable for graph algorithms; major shift on mind patterns.
Understanding Shell Script’s idiom: 2>&1
General usage:
1 | cat foo.txt > result.log 2>&1 |
- fd for stdout and stderr are 1 and 2 respectively
a > b
is a shortcut fora 1> b
and 1 here is fd value for stdout- you can use
&fd
to reference a fd value - therefore, using
2>&1
would redirect stderr to stdout, and1>&2
would do the opposite.