Scope control
Again, the book Test-Driven Development by Kent Beck provides me with an eye-opening experience. It explains how test-driven development is useful for scope control when developing.
Programmers are good at imagining all sorts of future problems. Starting with one concrete example and generalizing from there prevents you from prematurely confusing yourself with extraneous concerns. You can do a better job of solving the immediate problem because you are focused. When you go to implement the next test case, you can focus on that one, too, knowing that the previous test is guaranteed to work.
I’ve found this to be very true. Before starting to think this way, I way to often started writing a test (or even started implementing some feature), only to stray away to a number of different tasks; adding guard clauses for the function, writing a helper function that I might need, refactoring a related method, and so on. By writing a simple test and implement that piece of functionality (and only that), then write a new test and implement that, and so on, my coding has become much more focused and I move forward noticeably faster.
However, this doesn’t mean you should just ignore thoughts on potential related problems. Write them down to look at later — but don’t let them grab your attention for longer time than that. Keep pen and paper ready at all times.