Still, though, there are severe forms of depression that can become invulnerable to all the self-help approaches.
In code if something is wrong or not working right you know it can be fixed. Sometimes the fix is not easy, and requires lots of work, and research, and testing but after nearly ten years of coding experience I know that if something is wrong I can fix it. There is no problem in code which can't be solved. (Obviously excluding some things like the traveling salesman problem, etc.)
Real life isn't like that, because many factors are out of your control. You can not debug a relationship, or undo a mistake like you can roll back a code update.
At times I find myself retreating to the dependable, stable world of coding, in which changes can be implemented easily and quickly, and where mistakes are easily discovered and corrected. That's isn't necessarily a healthy thing though.
The science is pretty clear that a combination of medication and professionally-guided CBT has the most effective rates for treating depression, and that some specific treatments specifically don't work at all for some people.
http://therapists.psychologytoday.com/rms/content/therapy_me...
Which one is "most effective" (by what measure?) is very debatable.
Here's a Jungian critique of CBT ("Psychology's New God") :
http://hbmag.com/jungian-psychology-series-psychology’s-new-...
That said, if I can write code, I find that work is sometimes one of the most effective ways to stop the depression from worsening
There are people who think that depression means 'feeling low', and that if you try hard enough, you can 'snap out of it'. These people are idiots. It's not a matter of being strong enough or dedicated enough. For me, like most people with depressive illnesses, there will be times when I just plain can't. In my worst states I can barely remember what a for loop does, let alone code one. Accept that there will be times when you can't work, and make the most of the times when you can.
There is an approach called "behavioral activation" that my psychiatrist taught me. Basically, instead of saying "I'll do it when I feel better", you say "I'll do it so I'll feel better".
Doing things I didn't feel like doing, that felt almost impossibly difficult (like putting on real clothes and going outside) was probably the most effective tool I've ever had with dealing with depression.