It sounds simple, but it's hard to have perfect discipline. Especially if you have a strong bias towards action like I do.
It's shocking how applicable this is! Don't code an algorithm before having a firm grasp of the solution. Don't write code in an interview before you're sure you've uncovered everything your interviewer wants. Don't slam out a UI before understanding how all of the edge cases should act. Unless the point of the code is exploratory, the code should be a foregone conclusion by the time you start.
The more you practice this, the more you'll uncover bugs and underspecifications before you've spent days going down the wrong path.