Celan Code: Functions

This is the first chapter that did sound a bit out of date to me. Maybe not out of date but more… clearly strict in its judgements. As the title suggests it’s all about functions (or methods) and how they are a tool to manage abstraction in order to use it almost like a rethorical device to write out what is being done in the code.

Functions should

Function arguments

Common monads

Dyads and Tryads

Naming

Use good naming to express the intent of the function, the intent of the arguments and their ordering.

Side effects

Prefer pure functions (no side effects). Side effects are bad because:

Output arguments

Should be avoided.
They can be misleading when it’s hard for a caller to know if arguments are real arguments or output arguments.

Methods & Command Query Separation

Functions can either change the state of an object or answer a question about an object but not both.

Exceptions > Error codes

Try-Catch Block Extraction

Error handling is one thing. Functions should do one thing. As such: