clean code - two decades later

Abstract

A task is NOT DONE unless it’s CLEAN and TESTED. Mastering Code Smells is the first step towards Clean Code mastery.

Stuff that grew too big SRP violation:

  • monster method
    • functions shall be SMALL (smaller than a screen)
    • flat function (linear code with no indentation)
    • if
      • anemic else guard clauss
      • superficial if split in 2 functions
    • for
      • split loop use FP (Stream)
    • switch
      • is alone in a function, with one-line / case
    • catch
      • global exception handler
  • god class
    • > 200* lines
    • mixed layers of abstraction
    • split unrelated flows
  • many parameters
    • > 4
    • compute one inside
    • break method
    • value objects
      • small immutable, to change an attribute produce a modified copy
      • no persistent identity (PK)
      • equals uses all fields
  • primitive obsession
    • mitigate by creating micro-types
  • heavy lambda
  • flags
  • data clumps
  • feature envy
  • data classes
  • complex loop
  • accumulators
  • imperative FP
  • stream wreck
  • mutable data
  • confused variable