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

Clean Code 101

Clean Code 101

Writing code that is readable by humans is what we should all want, after all, the machine is not interested in what we write, it is important for the people with who we are in the team or the person who will continue the project after us. Talk is about the basics of Clean Coda and the rules that we should adhere to.

Marko Kunic

March 10, 2018
Tweet

More Decks by Marko Kunic

Other Decks in Programming

Transcript

  1. @kunicmarko20
    Clean Code 101

    View Slide

  2. @kunicmarko20

    View Slide

  3. @kunicmarko20
    - No abbreviation

    View Slide

  4. @kunicmarko20
    - No abbreviation
    - Intention revealing names

    View Slide

  5. @kunicmarko20

    View Slide

  6. @kunicmarko20

    View Slide

  7. @kunicmarko20

    View Slide

  8. @kunicmarko20

    View Slide

  9. @kunicmarko20
    - No abbreviation
    - Intention revealing names
    - // Comments === bad code (not always)

    View Slide

  10. @kunicmarko20

    View Slide

  11. @kunicmarko20

    View Slide

  12. @kunicmarko20

    View Slide

  13. @kunicmarko20

    View Slide

  14. @kunicmarko20
    - No abbreviation
    - Intention revealing names
    - // Comments === bad code (not always)
    - No dead code

    View Slide

  15. @kunicmarko20

    View Slide

  16. @kunicmarko20

    View Slide

  17. @kunicmarko20
    - No abbreviation
    - Intention revealing names
    - // Comments === bad code (not always)
    - No dead code
    - No magic numbers

    View Slide

  18. @kunicmarko20

    View Slide

  19. @kunicmarko20

    View Slide

  20. @kunicmarko20
    - No abbreviation
    - Intention revealing names
    - // Comments === bad code (not always)
    - No dead code
    - No magic numbers
    - No one-time variables

    View Slide

  21. @kunicmarko20

    View Slide

  22. @kunicmarko20
    - No abbreviation
    - Intention revealing names
    - // Comments === bad code (not always)
    - No dead code
    - No magic numbers
    - No one-time variables
    - No duplication

    View Slide

  23. @kunicmarko20
    DRY
    Don't repeat yourself

    View Slide

  24. @kunicmarko20
    Functions

    View Slide

  25. @kunicmarko20
    Functions
    - One responsibility

    View Slide

  26. @kunicmarko20
    Functions
    - One responsibility
    - Multiple smaller functions

    View Slide

  27. @kunicmarko20

    View Slide

  28. @kunicmarko20

    View Slide

  29. @kunicmarko20
    KISS
    Keep it simple, stupid

    View Slide

  30. @kunicmarko20

    View Slide

  31. @kunicmarko20

    View Slide

  32. @kunicmarko20

    View Slide

  33. @kunicmarko20

    View Slide

  34. @kunicmarko20

    View Slide

  35. @kunicmarko20

    View Slide

  36. @kunicmarko20
    Functions
    - One responsibility
    - Multiple smaller functions
    - No side effects

    View Slide

  37. @kunicmarko20

    View Slide

  38. @kunicmarko20
    Functions
    - One responsibility
    - Multiple smaller functions
    - No side effects
    - Only one level of indentation

    View Slide

  39. @kunicmarko20

    View Slide

  40. @kunicmarko20

    View Slide

  41. @kunicmarko20
    Functions
    - One responsibility
    - Multiple smaller functions
    - No side effects
    - Only one level of indentation
    - Early returns, avoid else

    View Slide

  42. @kunicmarko20

    View Slide

  43. @kunicmarko20

    View Slide

  44. @kunicmarko20
    Functions
    - One responsibility
    - Multiple smaller functions
    - No side effects
    - Only one level of indentation
    - Early returns, avoid else
    - Avoid flag arguments

    View Slide

  45. @kunicmarko20

    View Slide

  46. @kunicmarko20

    View Slide

  47. @kunicmarko20

    View Slide

  48. @kunicmarko20
    Law of Demeter

    View Slide

  49. @kunicmarko20

    View Slide

  50. @kunicmarko20

    View Slide

  51. @kunicmarko20

    View Slide

  52. @kunicmarko20
    Refactoring

    View Slide

  53. @kunicmarko20
    When?

    View Slide

  54. @kunicmarko20
    Always.

    View Slide

  55. @kunicmarko20

    View Slide

  56. @kunicmarko20
    Boy Scout Rule
    Leave the campground cleaner than you found it

    View Slide

  57. @kunicmarko20

    View Slide

  58. @kunicmarko20
    Want more details?

    View Slide

  59. @kunicmarko20
    The End

    View Slide