On a couple of recent occasions, I've written a bunch of code, only to have my colleagues correctly point out some decisions I'd made in writing it that made the code more complicated, and harder to reason about, than necessary (e.g. which logic should belong in which function, or what data structure I should use for something). I'm sure that this has amounted to a lot of wasted time. If I could have foreseen these decisions before writing code, or even just realized while writing code that I was making decisions that I ought to stop and think about, I wouldn't have made these more complicating choices, and wouldn't have had to spend all this time reworking my code.
(Of course, if I can learn a good lesson from this, the time will not have been wasted. Hence this post.)
The thing is: We'd spent significant time planning the structure of this project, with (I'd thought) clear documents and diagrams explaining what components we needed and how they would interact. When I started coding, I felt pretty well prepared, and confident that the thing would basically write itself.
So, HN: What steps do you take before setting out to write code? Are there principles that you use to decide that your plan/design is sufficiently detailed?
And, assuming there will be cases when the plan does not anticipate all design decisions: When you're coding, how do you avoid making decisions that will waste a lot of your time?