Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clean(er) Code

d4Rk
November 07, 2019

Clean(er) Code

You may think: Yet another Clean Code talk? 😱
=> Yay, for sure! 😊

As long as we don't dry the (software-)world sufficiently, everyone loves each other or at least listens to rock music, we carry around needless stuff and "solve" issues way to symptomatic, we'll (sadly) still have those talks.

d4Rk

November 07, 2019
Tweet

More Decks by d4Rk

Other Decks in Programming

Transcript

  1. ABOUT ME MARTIN “D4RK” STRAUB ▸ iOS developer @myposter !

    ▸ Guitar player @kentuckyschreit (ska/pop-punk) ▸ Husband ▸ Cat
  2. ABOUT ME MARTIN “D4RK” STRAUB ▸ ... ▸ ... ▸

    martin-straub.de ▸ iOS developer @myposter ! ▸ Guitar player @kentuckyschreit (ska/pop-punk) ▸ Husband ▸ Cat
  3. EVERY PIECE OF KNOWLEDGE MUST HAVE A SINGLE, UNAMBIGUOUS, AUTHORITATIVE

    REPRESENTATION WITHIN A SYSTEM. The Pragmatic Programmer DON’T REPEAT YOURSELF (DRY)
  4. DON’T REPEAT YOURSELF (DRY) WHAT’S IT ABOUT? ▸ Don’t repeat

    the knowledge ▸ Avoid contradictions ▸ One source of truth
  5. DON’T REPEAT YOURSELF (DRY) TYPES OF DUPLICATION ▸ Imposed duplication

    ▸ Inadvertent duplication ▸ Impatient duplication ▸ Interdeveloper duplication
  6. DUPLICATION IS FAR CHEAPER THAN THE WRONG ABSTRACTION. Sandi Metz

    (Teacher, writer, consultant, programmer)
  7. A SYSTEM’S KNOWLEDGE IS FAR BROADER THAN JUST ITS CODE.

    DON’T REPEAT YOURSELF (DRY) The Pragmatic Programmer
  8. DON’T REPEAT YOURSELF (DRY) BROADER USAGE ▸ Database schemas ▸

    Test plans ▸ Build system ▸ Documentation
  9. KEEP IT SIMPLE, STUPID (KISS) WHAT’S IT ABOUT? ▸ Most

    systems work best if they are kept simple rather than made complicated ▸ Simplicity should be a key goal in design ▸ Unnecessary complexity should be avoided ▸ The end-user doesn’t care how smart you are ▸ If you have to explain the product, it’s too complicated
  10. MAKE EVERYTHING AS SIMPLE AS POSSIBLE, BUT NOT SIMPLER Albert

    Einstein KEEP IT SIMPLE, STUPID (KISS)
  11. YOU AIN’T GONNA NEED IT (YAGNI) WHAT’S IT ABOUT? ▸

    80% of the time spent on a software project is invested in 20% of the functionality ▸ Prioritize (MoSCoW) ▸ No future coding ▸ No overengineering
  12. DRY VS. KISS & YAGNI SUMMARY ▸ DRY strives for

    abstraction ▸ KISS aims for simplicity ▸ YAGNI doesn’t want to do it at all ▸ Those principles compete with each other ▸ Find the right balance between DRY and KISS/ YAGNI
  13. ROOT CAUSE ANALYSIS (RCA) 1. REACTIVE MANAGEMENT ▸ React quickly,

    by treating the symptoms ▸ Goal: Ease the effects of the problem as soon as possible
  14. ROOT CAUSE ANALYSIS (RCA) 2. PROACTIVE MANAGEMENT ▸ Address the

    real cause instead of its symptoms ▸ Goal: Prevent problems from (re-)occurring
  15. ROOT CAUSE ANALYSIS (RCA) ROOT CAUSE ANALYSIS ▸ Identification and

    description ▸ Chronology ▸ Differentiation ▸ Causal graphing ▸ Next step: Trigger long-term corrective actions
  16. BY REPEATING WHY FIVE TIMES, THE NATURE OF THE PROBLEM

    AS WELL AS ITS SOLUTION BECOMES CLEAR. Taiichi Ohno ROOT CAUSE ANALYSIS (RCA) (“Father” of the Toyota Production System)
  17. ROOT CAUSE ANALYSIS (RCA) 5 WHYS Example: Ran through a

    red light. (problem) ▸ Why? - Late for work. (1st why) ▸ Why? - Woke up late. (2nd why) ▸ Why? - Alarm clock didn’t ring. (3rd why) ▸ Why? - Battery was empty. (4th why) ▸ Why? - Forgot to charge it. (5th why and root cause)
  18. ROOT CAUSE ANALYSIS (RCA) CONCLUSION ▸ Reactive management: quickly ease

    the symptoms ▸ Proactive management: actually fix the issue ▸ Only the latter can lead to a sustainable and reliable code base
  19. MAKE IT WORK, MAKE IT RIGHT, MAKE IT FAST. Kent

    Beck (Software engineer, creator of extreme programming, TDD, …)
  20. IT’S HARDER TO READ CODE THAN TO WRITE IT. Joel

    Spolsky (Co-founder of Stack Overflow)
  21. LOGIC DEPENDENCIES EXAMPLES ▸ App: Does the UI depend on

    the device’s orientation?
 ... or on parent view changes? ▸ Do you grab yourself a new beer every 15 minutes?
 … or every time the bottle’s empty?
  22. CLEAN(ER) CODE SUMMARY ▸ Play the principle game ▸ BUT:

    ▸ Principles are not rules ▸ Find the right balance ▸ Always use common sense ▸ Don’t get paralysed by overthinking things
  23. SOURCES DON’T REPEAT YOURSELF (DRY) ▸ https://pragprog.com/book/tpp/the-pragmatic-programmer ▸ https://thevaluable.dev/dry-principle-explained ▸

    http://verraes.net/2014/08/dry-is-about-knowledge ▸ https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction
  24. SOURCES KEEP IT SIMPLE, STUPID (KISS) ▸ https://en.wikipedia.org/wiki/Kelly_Johnson_(engineer) ▸ https://www.interaction-design.org/literature/article/kiss-keep-it-simple-stupid-

    a-design-principle ▸ https://championingscience.com/2019/03/15/everything-should-be-made-as- simple-as-possible-but-no-simpler
  25. SOURCES YOU AIN’T GONNA NEED IT (YAGNI) ▸ https://ronjeffries.com/articles/019-01ff/iter-yagni-skimp ▸

    https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it ▸ https://en.wikipedia.org/wiki/MoSCoW_method
  26. SOURCES ROOT CAUSE ANALYSIS (RCA) ▸ https://en.wikipedia.org/wiki/Root_cause_analysis ▸ https://en.wikipedia.org/wiki/5_Whys ▸

    https://en.wikipedia.org/wiki/Taiichi_Ohno ▸ https://kanbanize.com/lean-management/improvement/5-whys-analysis-tool
  27. SOURCES RCA (IMAGES) 2 ▸ https://www.jaguarforums.com/forum/x-type-x400-14/multiple-codes-read- puter-106645 ▸ https://psychologyhumor.tumblr.com/post/165200208492/express- psychotherapy

    ▸ https://michaelwtravels.boardingarea.com/2015/06/airline-fix-plane-duct- tape-uses/travelnews-111 ▸ https://www.solarwindsmsp.com/blog/results-show-controlnow-can-make- department-proactive
  28. SOURCES MAKE IT WORK, MAKE IT RIGHT, MAKE IT FAST.

    ▸ https://www.thetombomb.com/2018/05/17/make-it-work-make-it-right-make- it-fast ▸ http://engineerspro.blogspot.com/2016/06/career-information-regarding- mechanical.html ▸ https://www.pixwords.solutions/tl/solution/pagliko ▸ https://www.donanimhaber.com/spacex-falcon-roketine-ait-parcanin-dunya-ya- dustugu-anin-videosunu-yayinladi--115810
  29. SOURCES IT’S HARDER TO READ CODE THAN TO WRITE IT.

    ▸ https://www.joelonsoftware.com/2000/04/06/things-you-should-never-do- part-i
  30. SOURCES BUILD YOUR LOGIC ON DIRECT RELATIONS, NOT ON ASSUMPTIONS.

    ▸ https://www2.le.ac.uk/institution/lias/images/Fellows%203.jpg/view ▸ https://medium.com/@CodementorIO/good-developers-vs-bad-developers- fe9d2d6b582b
  31. SOURCES SUMMARY & SOURCES ▸ https://code.tutsplus.com/tutorials/3-key-software-principles-you-must- understand--net-25161 ▸ https://en.wikipedia.org/wiki/Analysis_paralysis ▸

    https://www.mr-maid.com/blog/hiring-bad-cleaning-service ▸ https://www.acadoo.de/woran-erkenne-ich-serioese-quellen.html ▸ https://en.wikipedia.org/wiki/LOLCODE