mc-bsh-cleancode
Links to Exercises and Solution in onlineGDB
Exercise DRY: https://onlinegdb.com/tPPLrqJSU
Solution DRY: https://onlinegdb.com/QcJ_cw2X7
Exercise: KISS: https://onlinegdb.com/w45SnUykW
Solution: KISS: https://onlinegdb.com/BGClenddV
Exercise SRP: https://onlinegdb.com/y_yMDipjp
Solution SRP: https://onlinegdb.com/ihIh3UoDY
Exercise OCP: https://onlinegdb.com/4NEazupFB
Solution: OCP: https://onlinegdb.com/QdeH-DwvI
Exercise LSP: https://onlinegdb.com/fbW_Okyjh
Solution LSP: https://onlinegdb.com/HIwZsa941
LSP Variant 2: https://onlinegdb.com/H7Q_8vQoC
LSP Variant 3: https://onlinegdb.com/klRcwjZ5q
LSP Variant 4: https://onlinegdb.com/K8peDGs-K
LSP Variant 5: https://onlinegdb.com/rHXOQBjt9
Exercise ISP: https://onlinegdb.com/fuNKkZTnP
Solution ISP: https://onlinegdb.com/EhJC-mFNF
Exercise DIP: https://onlinegdb.com/Y5D38RdWkU
Solution DIP: https://onlinegdb.com/DHvQm5rJ4E
Exercise FCOI_1: https://onlinegdb.com/QZ4KWULBr
Solution FCOI_1: https://onlinegdb.com/pqL8d5-KN
Exercise FCOI_2: https://onlinegdb.com/V5BYllaEg
Solution FCOI_2: https://onlinegdb.com/ktm7zkeXA
Exercise SMELLS: https://onlinegdb.com/NzwtARs1a
Solution SMELLS: TBD
Exercise CM: https://onlinegdb.com/uDZveTfza
Solution CM: https://onlinegdb.com/C1Rl6Tayw
Exercise MFBO: https://onlinegdb.com/lSw_tFc1V8
Solution MFBO: https://onlinegdb.com/n9yByCVIu
Exercise SIMPL: https://onlinegdb.com/Z2j3jvWNt
Solution SIMPL: https://onlinegdb.com/9N3HgD-sx
Exercise OTHER: https://onlinegdb.com/auRnKIiGx
Solution OTHER: https://onlinegdb.com/fgOenDvPV
Extra Demos based on Compiler Explorer
- https://godbolt.org/z/MEsq416c7
both versions joined into one (specify compile option -DX for solution) - https://godbolt.org/z/8Kb74Wfr1
comparison of both versions (based on assembly code) - https://godbolt.org/z/E5jq1MM9E (StatisticsFormatter)
- https://godbolt.org/z/bjhTr7 (DaysInMonth)
- https://godbolt.org/z/3z91zdxdb (defeat optimizer, eg. in performance analysis)
- https://godbolt.org/z/vvh8373G5 (more usages of lambdas)
- implement complex initializers
- reusable local functions
- structure sequential control flow
- ...
Some Internet Links related to Clean Code
Two YouTube-Videos "Pro & Contra Clean Code:
- https://www.youtube.com/watch?v=tD5NrevFtbU
"Clean" Code, Horrible Performance
covers C++ but looks exclusively at performance conseqiences of "clean code"
not at other impromements like readability, testability, modularity ... - https://www.youtube.com/watch?v=zVLuQAnNue8
Is Clean Code Really That Bad For Performance
covers C# and looks at how an optimizing compiler can revert things
which technically would make a "clean code" solutions less performant
A video by Scott Meyers which (among other things) covers C++ "perfect forwarding"
- https://www.youtube.com/watch?v=IqVZG6jWXvs
`std::move` doesn't move and `std::forward` doesn't forward
A video by Sean Parenr why to prefer algorithms over explicit logic and nestet loops:
A section of the C++-FAQ detailing the criteria when (and when not) "Inheritance" is appropriate
Books by Plauger and de Marco (Oldies but Goodies):
- "Programming on Purpose" (3 Books, one on "People" = Human Resources)
- "Peopleware" (dt. "Wien wartet auf Dich") mit kürzeren Essays
und "The Deadline" (dt. "Das Projekt") ein vollständiger Romen
Selected Info-Graphics (from https://tbfe.de/data/uploads/infographics)
- Example-OpenClosePrinciple (GoF "Template Methode Pattern")
classical solution with virtual member functions vs.
kind of "policy-based" solution with C++ templates
More Examples with the Compiler-Explorer:
- Optimize Beispiel 1
- Optimize Beispiel 2
- `typeid`, `boost::type_index` und Makro-Techniken
- Copy/Move delete/default
- FCOI Alternative 1 (central class extended with interfaces)
- FOCI Alternative 2 (multiple inheritance with overlapping base class)
- FCOI Alternativen 1 und 2 ("side by side" comparison of the above)
https://godbolt.org/z/vT1f3TeEM