Sadness, it turns out, may have benefits. A pair of psychologists believes that when we suffer setbacks, ruminating over them actually helps us recover and improve by forcing us to study painful situations, and come to logical conclusions about how they came about, and how to fix them.
The researchers, Andy Thomson and Paul Andrews, hypothesize that in depressed patients, a part of the brain responsible for attention and problem solving becomes more active. This implies that at least as far as the brain is concerned, figuring out why you hate your job isn't that different from solving a Sudoku puzzle.
Consider a young professor on tenure track who was treated by Thomson. The patient was having difficulties with his academic department. “This guy was used to success coming easy, but now it wasn’t,” Thomson says. “I made it clear that I thought he’d need some time to figure out his next step. His problem was like a splinter, and the pain wouldn’t go away until the splinter was removed.” Should the patient leave the department? Should he leave academia? Or should he try to resolve the disagreement? Over the next several weeks, Thomson helped the patient analyze his situation and carefully think through the alternatives. “We took it one variable at a time,” Thomson says. “And it eventually became clear to him that the departmental issues couldn’t be fixed. He needed to leave. Once he came to that conclusion, he started feeling better.”
It also seems the relationship between sadness and analytical thinking can easily work the other way:
In a survey led by the neuroscientist Nancy Andreasen, 30 writers from the Iowa Writers’ Workshop were interviewed about their mental history. Eighty percent of the writers met the formal diagnostic criteria for some form of depression. …
When people are stuck in the ruminative spiral, their achievements become invisible; the mind is only interested in what has gone wrong. While this condition is typically linked to withdrawal and silence — people become unwilling to communicate — there’s some suggestive evidence that states of unhappiness can actually improve our expressive abilities. Forgas said he has found that sadness correlates with clearer and more compelling sentences, and that negative moods “promote a more concrete, accommodative and ultimately more successful communication style.” Because we’re more critical of what we’re writing, we produce more refined prose, the sentences polished by our angst. As Roland Barthes observed, “A creative writer is one for whom writing is a problem.”
You could easily replace 'writing' in these examples with 'writing software,' and you'd be describing every really good programmer I've ever met.