Abstract


  • Codes that are written in a way that makes it simple, concise, and expressive

Important

Clean code should minimise cognitive load as much as possible, that means it takes less effort for new joiners or ourselves to get a sense of the codes.

Never Nester


Quote

If you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program - Linux kernel style guidelines

  • The idea to to avoid deep nesting in program, to make code more readable and easier to maintain
  • There are two ways to avoid deep nesting - extraction & Inversion

Extraction

  • Extracts nested logic out and place it inside its own Function

Inversion

  • Replace if-else with return

References