Here are my notes on Rob Harrop’s presentation about functional programming.
Why is Functional Important?
- it’s declarative
- you write what you want to achieve, rather than give instructions how to achieve it
- express solutions, and you do not worry about individual steps
- functional fits well with Agile methodology
- testing is much easier (because of purity, no side-effects)
- self-content while you are working
- e.g. parallelization
- often the reason why people switch to functional
Imperative vs Functional Languages
- function application (calculations to data), not state change
- immutable state (makes testing easier)
- recursion not looping
- descriptions (of solutions), not statements
- focus on decisions (instructions), and state change
- mutable state
- higher-order functions
- pure functions (the same args in will always lead to the same results)
- type systems (Haskell: strong typing; Erlang, LISP: loosely typed)
- strict/lazy evaluation
The primary focus should be on the domain and domain logic.
- ubiquitous language
- strategic design (identify which bits are harder to model and put time on it)
Domain-driven with imperative programming leads to anxiety. Always wondering if you got your model right, because there are a myriad of ways to implement a solution.
- the core concepts still apply
- everything is just a function or data structure
Why is Functional Better?
- fewer concepts (no factories, no patterns)
- easier concepts
- lower model overhead
- UML doesn’t really work for functional
- fortunately, we all know how to model in functional languages