Procedure
- Identify input, output, assumptions
- Create test cases: Try cover all edge cases
- Repeat until sufficient:
- Hypothesize solution: State in plain english
- Implement solution, and test. Fix bugs if any
- Analyze solution’s complexity. Identify inefficiencies
- Hypothesize new solution to eliminate the efficiency
- Prefix comments describing code that handles a specific case with “CASE: ”
- Usually written after a logic that singles out a specific case. e.g.,
if val < min: # CASE: val is new lowest
- A binary case DOES NOT require an opposite case to be implicitly written. For example, the opposite case is not written in the
else line below:
if val < min: # CASE: val is new lowest
...
else:
...
- Prefix comments describing invariants following a code that eliminates a case with “INVARIANT: ”
- Usually written in the same line or below the corresponding case comment.
- Binary cases DOES NOT require an assert note. e.g.,
CASE: List is empty implies an INVARIANT: List is not empty
if linked_list.head is None: # CASE: List is empty
...
return
# INVARIANT: List has at least 1 element
- Prefix note comments with “NOTE: ”