Sometimes I look at a piece of code or a design or a problem that I want to solve and I can see the ultimate goal for how I want to approach it. I can see it very clearly. When this happens, I go straight to the end goal and do it the way that I can see it in my mind. When this happens it's great and I can get a tremendous amount accomplished in a very short time. It's great when it happens.
Unfortunately, it doesn't always happen that way.
Sometimes I look at a piece of code or a design or a problem and I know that it can be so much better. I know that there is a smooth and elegant way to approach it. I can feel it in my bones. I just can't see it yet.
The problem with these times when I know there is an elegant solution but I can't see it, is that it's like writers block for me. It will make me sit and stew and do nothing, because I can't quite formulate exactly what I want to do.
I've found that the best way to get past this writers block is to just force myself to do something. Anything. Just start with small changes, or pieces of code and gradually iterate through changing them and getting them closer and closer to where I need to end up.
It's like that scene in Finding Forrester where Sean Connery tells Rob Brown to just start typing. He starts with a paragraph from an existing paper, and then it starts to flow from himself.
Start with something. Even just a simple loop that has nothing in it. Get it to compile. Add more to it. Compile it, run it, extend it. It starts to flow. Then you can get it to do what you need it to do.
Iterate. Don't be afraid to start small and grow it into something bigger with many, many iterations.