3 Programming Paradigms383 2018-08-12 02:31
Structured programming vs. OO programming vs. Functional programming
Structured programming is discipline imposed upon direct transfer of control.
- Testability: software is like science: Science does not work by proving statements true, but rather by proving statements false. Structured programming forces us to recursively decompose a program into a set of small provable functions.
OO programming is discipline imposed upon indirect transfer of control.
- Capsulation, inheritance, polymorphism(pointers to functions) are not unique to OO.
- But OO makes polymorphism safe and convenient to use. And then enable the powerful plugin architecture with dependency inversion
- Source code denpendencies and flow of control are typically the same. However, if we make them both depend on interfaces, dependency is inverted.
- absolute control over the direction of all source code dependencies in the system. They are not constrained to align those dependencies with the flow of control.
- Interfaces empower independent deployability
Functional programming: Immutability. is discipline imposed upon variable assignment.
- Why important? All race conditions, deadlock conditions, and concurrent update problems are due to mutable variables.
- Event sourcing is a strategy wherein we store the transactions, but not the state. When state is required, we simply apply all the transactions from the beginning of time.