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,
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.
A direct transfer of control
goto statement is discouraged or removed.
Instead of using a
goto statement 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.
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.
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.
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.