Mathematicians and philosophers often make terrible programmers. They also tend to write gibberish even in English. (Ok, I do not know if it is a fact, but stay with me.)
A terrible way of programming is to try to hold the entire problem in your head and to put it into code in one shot. Why? Because you are almost certainly overestimating your brain. Your mind can only cope with few parameters at a time.
Here is how you have to program:
- If you have the luxury to start fresh, start small. Otherwise, make sure you understand and respect the code you start with.
- Identify specific changes you want to implement. Small changes! Then implement them. Then test them!
You should never redesign working software from the ground up without incremental testing. Never. Even if you work alone.
Interestingly, I also write my papers incrementally, fixing small things one after the other. No other way works for me.