liveBook · Manning

Functional, stateless philosophy

As explained in The Art of Unit Testing 3e

A programming paradigm that emphasizes function composition, expressions, and minimizing mutable state and side effects.

Functional design organizes code around functions and offers simplicity, clarity, and provability as alternatives to object-oriented design. It also brings a learning curve. section 3.4

Use the philosophy as a practical design option rather than an absolute rule:

  • Choose between functional and object-oriented designs according to what works for the team; the underlying patterns can often be translated between styles. section 3.4
  • Expect additional caller responsibility when solving a dependency problem by adding a function parameter; the result can feel overly chatty. section 3.4
  • Use functional techniques for injecting stubs and mocks when they make dependencies easier to control in tests. section 3.4 section 4.6

Function-level dependency injection

Adding a parameter can remove a function's dependency, but every caller must then know how to handle the dependency, such as dates. The technique solves one problem while increasing communication between callers and functions. section 3.4

How The Art of Unit Testing 3e covers it

How deep it goes
Contrasts functional and object-oriented choices, explaining benefits and learning costs without developing implementation internals.
Examples
Uses function-level dependency injection and mock injection as practical functional-design examples.
What you can do after
Apply functional or object-oriented designs selectively when breaking dependencies and injecting stubs or mocks.
How it connects
Connects functional design with unit testing, dependency injection, stubs, mocks, and object-oriented design.

Also explained in

Compare how 19 books explain functional, stateless philosophy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Unit Testing 3e. The section links point to the parts of the book it draws on.