It usually helps to have a systematic mathematical model for the problem you are trying to solve, and systematic mathematical models for the sub-problems into which the full problem is decomposed. It is frequently better to conceive of each step in the program as ensuring some property is invariant rather than conceiving each step as performing some action.
It is probably better not to think of yourself as a coder or a programmer; consider yourself a problem solver with mathematical skills and move on to there.
Always convince yourself that the problem you are trying to solve has a solution.