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

  2. @kunicmarko20

  3. @kunicmarko20 - No abbreviation

  4. @kunicmarko20 - No abbreviation - Intention revealing names

  5. @kunicmarko20

  6. @kunicmarko20

  7. @kunicmarko20

  8. @kunicmarko20

  9. @kunicmarko20 - No abbreviation - Intention revealing names - //

    Comments === bad code (not always)
  10. @kunicmarko20

  11. @kunicmarko20

  12. @kunicmarko20

  13. @kunicmarko20

  14. @kunicmarko20 - No abbreviation - Intention revealing names - //

    Comments === bad code (not always) - No dead code
  15. @kunicmarko20

  16. @kunicmarko20

  17. @kunicmarko20 - No abbreviation - Intention revealing names - //

    Comments === bad code (not always) - No dead code - No magic numbers
  18. @kunicmarko20

  19. @kunicmarko20

  20. @kunicmarko20 - No abbreviation - Intention revealing names - //

    Comments === bad code (not always) - No dead code - No magic numbers - No one-time variables
  21. @kunicmarko20

  22. @kunicmarko20 - No abbreviation - Intention revealing names - //

    Comments === bad code (not always) - No dead code - No magic numbers - No one-time variables - No duplication
  23. @kunicmarko20 DRY Don't repeat yourself

  24. @kunicmarko20 Functions

  25. @kunicmarko20 Functions - One responsibility

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

  27. @kunicmarko20

  28. @kunicmarko20

  29. @kunicmarko20 KISS Keep it simple, stupid

  30. @kunicmarko20

  31. @kunicmarko20

  32. @kunicmarko20

  33. @kunicmarko20

  34. @kunicmarko20

  35. @kunicmarko20

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

    No side effects
  37. @kunicmarko20

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

    No side effects - Only one level of indentation
  39. @kunicmarko20

  40. @kunicmarko20

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

    No side effects - Only one level of indentation - Early returns, avoid else
  42. @kunicmarko20

  43. @kunicmarko20

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

    No side effects - Only one level of indentation - Early returns, avoid else - Avoid flag arguments
  45. @kunicmarko20

  46. @kunicmarko20

  47. @kunicmarko20

  48. @kunicmarko20 Law of Demeter

  49. @kunicmarko20

  50. @kunicmarko20

  51. @kunicmarko20

  52. @kunicmarko20 Refactoring

  53. @kunicmarko20 When?

  54. @kunicmarko20 Always.

  55. @kunicmarko20

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

    found it
  57. @kunicmarko20

  58. @kunicmarko20 Want more details?

  59. @kunicmarko20 The End