Coding Tactic: Create Reliable Scenarios
When a function begins, the inputs can be lots of things you don’t want to deal with. Narrow them down to a reliable scenario that you do want to handle.
This may be
- early-returns (e.g.
if (x < 17) return;
… now you knowx >= 17
) - reshaping data (e.g.
phone = parsePhoneNumber(userInput);
… now you know you have a valid phone number) - breaking the problem down into smaller functions
In all cases, we’re limiting the noise so we can focus on getting a small piece of the puzzle correct.