Uncle Bob Clean Code Checklist Functions

  • Functions
    • Has same level of abstractions (high level abstractions and primitive structures together)
    • Should follow the same methodology as news articles - the deeper you go into them, the more details you get.
    • Should be small (usually 2-6 lines)
    • Should do 1 thing - you cannot extract another function from it.
    • Shouldn't have more than 1-2 indents
    • Shouldn't have more than 3 arguments
    • Shouldn't have bool input arguments
    • Shouldn't have input arguments that are used as outputs
    • Shouldn't contain switch/if-else statements (prefer [[polymorphism]], Open-Closed Principle, [[NullObject]])
    • Shouldn't have [[side-effects]] (file.open without close etc)
    • Should have command/query separation. ([[Queries]] shouldn't modify the state[[,]] commands shouldn't return data).

Basically split your functions into more functions until you can't. Then probably you'll see hidden classes that you need to move these functions to. (Timestamp 1:00:23)

  • Exceptions
    • Always prefer [[exceptions]] over [[error codes]]
    • [[Function body]] should only contain [[try&catch block]] if there is one.
    • Don't use nested try&catch blocks

Flashcards

  • Has same level of abstractions (high level abstractions and primitive structures together) together
  • How big should an average function be::small (usually 2-6 lines)
  • What should a function do?::It should do only 1 thing. You cannot extract another function from it.
  • How many indents shouldn't the function exceed?::It shouldn't exceed 1-2 indents
  • How many arguments should a function have::A functions shouldn't have move than 3 arguments
  • A function shouldn't have boolean input arguments
  • A function shouldn't input arguments that are used as outputs.
  • A function shouldn't contain switch/if-else statements. Prefer polymorphism, open-closed principle, null-object.
  • A functions shouldn't have side-effects like opening file without closing it.
  • Functions should follow the command/query seperation. Queries shouldn't modify the state, commands shouldn't return data.
  • Always prefer exceptions over error codes.
  • Function body should only contain try&catch block if there is one.
  • Don't use nested try&catch blocks.