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

Clean Code

Clean Code

Growing healthy systems with "clean" principles.

Michael Hamrah

March 12, 2014
Tweet

More Decks by Michael Hamrah

Other Decks in Programming

Transcript

  1. Time it takes to add one line of code: 10

    seconds Time it takes to add one file: 30 seconds? Time it takes to understand 500 lines of code? Time to understand 500 files?
  2. BUT FIRST, EXECUTION CONTEXT Do you understand what is happening?

    Not a language problem: Ruby, Go, Js, Scala. All readable. Does your friend understand what is happening? Would a stranger understand what is happening?
  3. AKA ONION ARCHITECTURE Control Dependencies Db is not the center

    of the app Framework is not the center of the app Separate Concerns Focus on important code
  4. HOW EASY IS IT TO REPLACE X? THE DEPENDENCY RULE:

    SOURCE CODE DEPENDENCIES CAN ONLY POINT INWARDS. The name of something declared in an outer circle must not be mentioned by the code in the an inner circle. That includes, functions, classes, variables or any other named software entity.
  5. LEAN ARCHITECTURE ( A M A Z O N )

    DCI: DATA, CONTEXT, INTERACTION ( W I K I P E D I A) Split what a system is (data) from what a system does (interaction) Context is the glue Think of a waiter in a restaurant
  6. IF A TEST NEVER FAILED, DOES IT EVER REALLY PASS?

    IT'S ABOUT THE WHY AND THE HOW Are you forcing a puzzle piece?
  7. TEST FIRST: EVOLVE YOUR CODE What do you need to

    happen? How easy is it to make it happen? Tell a story Look for smells! Refactor!
  8. IN SUMMARY Conforming to these simple rules is not hard,

    and will save you a lot of headaches going forward. By separating the software into layers, and conforming to The Dependency Rule, you will create a system that is intrinsically testable, with all the benefits that implies. When any of the external parts of the system become obsolete, like the database, or the web framework, you can replace those obsolete elements with a minimum of fuss.