2 ms·
I would give almost the opposite advice: Whenever you feel like writing a comment explaining why you're doing something, step back and consider if you can refa
by continuational 9y ago
I would give almost the opposite advice:
Whenever you feel like writing a comment explaining why you're doing something, step back and consider if you can refactor the code so that it becomes self documenting. Code and comments get out of sync easily.
Instead of checking for preconditions, step back and consider if you can make the illegal states unrepresentable. If you have a decent type system available (sum types, no nulls), that's often straightforward.
The best peice of code, the best test and the best comment is the one you didn't have to write because of good design.