If I'm feeling miserable about the code, I generally shift gears and work on a more straightforward area of my project. Ideally some class which is self-contained and easier to reason about. More often than not, an hour of that gets me back into "flow" and I can go back to what I was originally doing.
As others have said go do something else if that can happen then switch domains and work on something you consider fun either because you like the domain or the challenge.
Trying to push through with coding doesn't work.
Another trick would be to step out of the editor and hit the white board while on your feet. Programming isn't typing and if you are trying to figure out a problem at the keyboard theres a good chance you already failed (unless your learning the language). Get it on paper/chalk/whiteboard and reason about it, talk about it with someone or a rubber duck.
5 comments
[ 3.1 ms ] story [ 22.0 ms ] threadIf you're in a place that forces you into insane hours for long stretches, start looking for an alternative. When you find a decent one, take it.
Eat when you are hungry.
Sleep when you are tired.
Program when the time is right.
Trying to push through with coding doesn't work.
Another trick would be to step out of the editor and hit the white board while on your feet. Programming isn't typing and if you are trying to figure out a problem at the keyboard theres a good chance you already failed (unless your learning the language). Get it on paper/chalk/whiteboard and reason about it, talk about it with someone or a rubber duck.
Walks in the woods are great for thinking and problem solving.