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.
The implementations here use Scala to take advantage of its hybrid object-oriented and functional design, which caters to both imperative and functional patterns.
adjective
We use RĂșnar Bjarnason's definition of referential transparency
adjective
- 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
noun
- a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.
verb
- to restructure software by applying a series of refactorings without changing its observable behavior.
IO
malloc
and free
with a
monad