Summary of Clean Architecture Part II
After reading Clean Architecture, I've had a trouble understanding differences of each programming paradigm;
Let me share a summary of Clean Architecture Part II, Starting with the Bricks: Programming Paradigms.
Firstly, what is,
A Programming Paradigm?
It is a programming discipline, used to decide which form of programming structure (SP, OOP, FP) to use.
Each paradigm places a constraint on a programmer.
Disciplines imposed by each paradigm
A direct transfer of control Example:
gotostatement is discouraged or removed. Instead of using a
gotostatement for an unconstrainted control flow, programmers are forced to use (now familiar) constructs such as
An indirect transfer of control Example: Function pointers are eliminated. OOP provides a plug-in architecture with a use of polymorphism. Polymorphism also enables a programmer to change the code dependencies with Dependency Inversion Principle.
A variable assignment Example: Cannot assign a new value to a variable.
What problem(s) each paradigm solves
SP causes noodlers (preventing spaghetti codes) to become an endangers species How? By discouraging the use of goto and encouraging functional decomposition and use of data structures.
Complete control over code dependencies and flows. How? By using dependency inversion with the use of polymorphism.
All race/deadlock conditions, and concurrent update problems. How? Problems mentioned above are caused by variable mutation. FP prevents variable assignment, thus those problems can't occur.
Programming Paradigm Use Cases
Initially, I thought about when to use each paradigm. When you consider a software architecture as a whole, it makes more sense to use each one appropriately.
So as an example, write low-level methods with SP principles, and separate immutable components (written with FP) from mutable components to mitigate resource contention and control flows with OOP.
- Science theories and laws are not provable, only falsifiable.
- Encapsulation, Inheritance, and Polymorphism concepts are not introduced in OOP! - These concepts were available in C, but the usages were unsafe and OOP made it safer/easier to use.
- Access modifiers,
protectedin OOP are just a hack necessitated by technical reasons! - C header files hid member variables but C++ header files had to expose member variables because C++ compilers have to know the size of the instances of each class. Even worse, modern OOP languages such as C#/Java do not separate a class declaration from its implementation therefore, those modifiers are necessary evils.
- In FP, variables do NOT vary!
- Each paradigm tells a programmer what NOT to do.
- Clean Architecture is a book written by Robert C. Martin, aka Uncle "Bob".
- Coding Blocks guys talk about it in more detail in Episode 69 – Clean Architecture – Programming Paradigms.