As programmers, we’ll always reward the simplest solution to a problem. There is a really satisfying feeling that comes from taking something you thought was complicated and boiling it down to its essence, seeing pieces of the problem dissolve as you code.
On the other hand, there is always an uneasy tendency dragging in the other direction. The more you work on an answer, the more you want it to be right. This commitment makes you less willing to turn back and accept that you need a rethink.
Do youself a favor, next time you hit a rut and are trying to force a solution to be correct despite the bad feeling you have about it.. Stash your code and start over. Take a fresh stab at the base of the problem from a different angle. If it feels good, keep going with it. If it feels wrong, either start again or consider what mixed pieces of this solution and your original work well together.
This is software development for a reason. If we were just putting together pieces with no regard for maintainability, readability, or elegance we probably wouldn’t be needed any more. Be like a designer, and don’t stop until you make something you love.