Defensive Coding
Essential Reading
Essential Video
Lab
Notes
- Assertions
- An expression which is supposed to be true at a particular point in a program
- categories:
- precondition
- something that must be true at the start of a function
- postcondition
- something that the function guarantees is true when it finishes
- invariant
- something that is always true at a particular point inside a piece of code
- test-driven development (TDD)
- create tests before writing the function or code
- helps avoid confirmation bias in writing tests
- produces better code faster
- General defensive coding concepts
- never trust data
- validate everything
- robust error handling
- multiple catch blocks for different exceptions with robust info and fixes