Knaph

Writing Correct Code

Map

Arrows point from what you learn first to what it opens. Point at a concept to light up its chain and where it comes back deeper. Right-click a concept (or press and hold it) for its lessons and stories.

  • Proven to depth123
  • Open
  • Locked
  • Comes back deeper

Learning path

In the order the concepts build on each other.

  1. Edge casesLockedInputs at the edges of what a program handles - exactly on a boundary, zero, a value that shouldn't happen - where most bugs in decisions hide.Opens after: Conditionals
  2. ExceptionsLockedThe way a running program signals that something went wrong, so that code can catch the problem and carry on, or stop with a clear message instead of carrying on with nonsense.Opens after: Type conversion, Functions in code
  3. Type annotationsLockedNotes in the code saying what type each parameter, return value or name is meant to have, so that people and tools know what a function wants and gives back.Opens after: None, Dictionaries
  4. Code readabilityLockedWriting code so that the next person, often yourself months later, can quickly understand what it does and why: clear names, docstrings, comments that explain, one shared style.Opens after: Type annotations
  5. Static and dynamic typingLockedWhether a program's types are checked before it runs, by a compiler or a type checker, or only as each line runs, as Python does.Opens after: Type annotations
  6. TestingLockedChecking that a program does what it should, by deciding the right outputs for chosen inputs first and letting code such as assert compare them every time the program changes.Opens after: Edge cases, Exceptions
  7. DebuggingLockedFinding out why a program does the wrong thing, by reading its error messages, guessing a cause, and checking the guess against the program's real values.Opens after: Error messages, Testing

Connections to other domains