Base de cours autour des principes SOLID et STUPID
STUPID Code !Make it SOLID
View Slide
Principles, not laws
You’re code is STUPID !
STUPID
STUPIDingleton
Global State
Hidden dependencies
But not impossibleDifficult to test
STUPIDight coupling
Interaction level betweencomponents
Difficult to change
Difficult to reuse
Difficult to test
Avoiding “new”
STUPIDntestability
Everything must be easyto test
If you can’t test, theproblem is about design
STUPIDremature Optimization
Premature optimization isthe root of all evil
Optimize only if it’snecessary
Optimize timely
Don’t do it (yet) !
Readability > Optimization
STUPIDndescriptive naming
Name properly
Names came from yourdomain
Don’t abbreviate
Don’t prefix/suffix
The length of a variablename should beproportional to its scope.The length of a function orclass name is the inverse.
“You should name avariable using the same carewith which you name afirst-born child.”
Programming languages arefor humans, not forcomputers
Code > Comments
Code = How
Tests = What
Comments = Why
STUPIDuplication
Be lazyDon’t Repeat Yourself
Most of timeCopy/Paste is bad
Use a Copy/PasteDetector
Make it SOLID plz !
SOLID
SOLIDingle responsability
Every class should have asingle responsibility
Never be more than onereason for a class tochange
God classes
Don’t make yourcontroller be God Objects
Avoid Mutators
Ask yourself what is classresponsablity
Keep it as small aspossible
SOLIDpen/Close
Open for extension, butclosed for modification
extend > modify
setup > modify
SOLIDiskov substitution
Objects should bereplaceable withinstances of theirsubtypes without alteringthe correctness of theprogram.
A square is NOT arectangle
The mouse case
SOLIDnterface segregation
Many clients > OneGeneric Client
Don’t over-interface
SOLIDependency injection
High level modulesshould not depend on lowlevel modules. Bothshould depend onabstractions.
Abstractions should notdepend on details. Detailsshould depend onabstractions.
Be pragmatic
Exercice
git clonehttps://github.com/gbprod/solid-stupid.git