Refactoring is one of the important processes in software development.
The following is an exploration of code written in familiar imperative programming patterns, and refactored using a counterpart functional programming pattern. The goal is to build up a handy bidirectional map of corresponding imperative and functional patterns.
These patterns use Scala to take advantage of its hybrid object-oriented and functional design, which caters to both imperative and functional patterns.
We use Rúnar Bjarnason’s definition of referential transparency
- an expression e is referentially transparent if for all programs p, every occurrence of e in p can be replaced with the result of evaluating e without changing the result of evaluating p.
We use Martin Fowler’s definitions of refactoring
- a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.
- to restructure software by applying a series of refactorings without changing its observable behavior.
freewith a monad