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

Clean Code Developer Red Grade

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Clean Code Developer Red Grade

Learn the principles and practices of Clean Code Development.

Mark Paluch

July 18, 2013

Transcript

19 slides
  1. Clean Code Developer A way to better code Session 01

    https://github.com/mp911de/CCD Donnerstag, 18. Juli 13
  2. Grade • 7 Grades • Make your progress visible •

    0. Black: Interested in CCD • 1. Red: First Steps • 2. Orange: Steady Improvement • 3. Yellow: Intermediate • 4. Green: Productivity and Automation • 5. Blue: Test first, concepts • 6. White: Clean Code Developer Donnerstag, 18. Juli 13
  3. Red Grade • Principles • Don‘t Repeat Yourself (DRY) •

    Keep it simple, stupid (KISS) • Beware of optimization! • Favor Composition over Inheritance (FCoI) • Practices • Boy Scout Rule • Root Cause Analysis • Use a source code management system • Apply simple refactoring patterns • Reflect daily Donnerstag, 18. Juli 13
  4. Don‘t Repeat Yourself (DRY) • Every duplicate causes effort and

    the need of maintenance • More code = more complexity • Reuse where possible double rate1 = calculateRate(1, 12); double rate2 = calculateRate(2, 24); double rate3 = calculateRate(3, 36); double rate4 = calculateRate(10, 120); Donnerstag, 18. Juli 13
  5. Keep it simple, stupid (KISS)¶ • Life is simple –

    keep your code simple • A genius is result = not(xor(bithackA, bithackB)) and not a = !A ^ B; • More code is sometimes better to understand • Don‘t let your method names lie public String toString() { if (im == 0) return Double.toString(re); if (re == 0) return im + " I"; if (im < 0) return re + " - " + (-im) + " I"; return re + " + " + im + " I"; } Donnerstag, 18. Juli 13
  6. Beware! Optimization! • Premature optimization is the root of a

    lot evil • Don‘t try to optimize for 2% performance, to get 5ms one-time performance • Improving performance by 500% to reduce runtime by days or weeks is something different Donnerstag, 18. Juli 13
  7. Optimization Rules • Rule 1: Don't do it. • Rule

    2 (for experts only): Don't do it yet. Donnerstag, 18. Juli 13
  8. Favor Composition over Inheritance (FCoI) • Loose coupling • Easier

    testability • Easy reuse • Super-Classes in between are strong coupled in both directions Donnerstag, 18. Juli 13
  9. Boy scout rule • Leave your place cleaner than you

    entered it • Clean up the code around your changes • Small cleanups – huge effect • Rotten code starts also small – if no one cares • But you care! Donnerstag, 18. Juli 13
  10. Root Cause Analysis • You better know the cause of

    something (bug, feature) • No knowledge leads to wrong conclusions • Wrong conclusion • wrong implementation • Bug • Don‘t cure symptoms else your patient dies • Knowledge about the inner voodoo Donnerstag, 18. Juli 13
  11. Apply simple refactoring patterns • Extract Method • Rename a

    Method/Class • Move a Method/Class • Think about the Boy scout rule • Code Examples https://github.com/mp911de/CCD Donnerstag, 18. Juli 13
  12. Reflect daily • Measure your improvement • If you don‘t

    plan it, you don‘t do it • What have I done today? • What can I improve? • What do I want to try tomorrow? Donnerstag, 18. Juli 13
  13. Image Credits Table of Contents: © by Michael Kappel http://michaelkappel.com

    Bands: © by Alexander Herzog Computer Geeks: Adam Breckler Blue Screen: Anders Rune Jensen Cable Chaos: Stefano Liboni Donnerstag, 18. Juli 13

More Decks by Mark Paluch

Other Decks in Programming