Clean Code

Clean Code

Growing healthy systems with "clean" principles.

3ca5501cb61a4251bd1e6f0a878bb8d4?s=128

Michael Hamrah

March 12, 2014
Tweet

Transcript

  1. CLEAN CODE GROWING HEALTHY SYSTEMS / Michael Hamrah @mhamrah

  2. None
  3. 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?
  4. WHAT TO DO? CLEAN/ONION ARCHITECTURE DATA, CONTEXT AND INTERACTION EVOLVING

    CODE THROUGH TESTS
  5. 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?
  6. CLEAN ARCHITECTURE

  7. 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
  8. / Clean Architecture Onion Architecture

  9. 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.
  10. 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
  11. IF A TEST NEVER FAILED, DOES IT EVER REALLY PASS?

    IT'S ABOUT THE WHY AND THE HOW Are you forcing a puzzle piece?
  12. 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!
  13. 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.