6.005: Software Construction
Safe from bugs
Easy to understand
Ready for change
Immutability (immunity from change) is a major design principle in this course. Immutable types are types whose values can never change once they have been created. (At least not in a way that’s visible to the outside world – there are some subtleties there that we’ll talk more about in a future class about immutability.)
- Write a specification for the function.
Write tests that exercise the specification.
Write the actual code. Once your code passes the tests you wrote, you’re done.
Writing tests first is a good way to understand the specification. The specification can be buggy, too — incorrect, incomplete, ambiguous, missing corner cases. Trying to write tests can uncover these problems early, before you’ve wasted time writing an implementation of a buggy spec.