Sleep solves everything

Will I ever learn this lesson? Throughout my programming career, I will ruminate on a tricky problem for hours at a time to no avail. Banging my head against a programming problem doesn't help. Time and time again, I find, the next morning, that the problem is trivial and I fix it in short order.

Learning and problem solving are related to sleep. I see the same thing in playing music. I play woodwinds and really enjoy the tricky fast passages common in Baroque Music. Sometimes I will struggle for hours over some awkward fingering that I just can't seem to get. In music, it's called wood shedding: sitting somewhere and playing the same passage over and over until you get it right. Sometimes that works, sometimes it doesn't.

What does work every time? Practicing for a while, moving on to something else and then sleeping. The next morning, I find that performing the complicated or tricky fingering is much easier. If hack at it too much, I reinforce the errors instead of the correct fingering.

This is so true in programming. Case in point yesterday and today with a problem in the Socorro Middleware. We discovered the problem and I stepped up to fix it. Forty minutes later I submitted my patch only to find that it made the Middleware explode in a completely unrelated place. There seemed to be no logical connection between the work that I did and the failure. I banged my head on that problem for hours and hours pushing myself into a fourteen hour work day.

This morning, I looked at the problematic code and said, “I wonder...”, then spotted the problem, made the trivial fix, pushed the code to github, watched the Jenkins job feed it through the battery of tests and voilĂ  it passed.

 It is a lesson that is hard to learn. Maybe if I were to sleep on it, I'd learn it.