Category Archives: programming

Sleep and my attempts at hacking it

A few quick notes from a whole bunch of sleep related books I’ve been reading, and some of my sleep/wake experiments I’ve been running on my own. It may be relevant for most people but more so for programmers like me.

You don’t need 8 hrs of continuous sleep, most current research seems to suggest that for every 2 hrs of wake you need 1 hour of sleep. Sleepiness increases as the wakeful hours build up. This means that catching naps is quite effective in being alert. One of the biggest thing to look out for is a full sleep cycle, in which you pass from light sleep to deep sleep and then REM sleep. REM sleep is the last stage of each cycle and possibly the most important (studies have shown that ability to learn goes drops dramatically when deprived of REM sleep).  It is also the easiest to awake at the end of the sleep cycle (depth of sleep gets lower as you approach REM sleep), typically this period is about 90 minutes to 110 minutes long. You feel freshest waking up at the edge of your sleep cycles, and disoriented when woken in the middle of deep sleep. The trick is to sleep in a quite room and wake up naturally (as against using alarm).

Color of light during the day and evening before sleep is very important, lots of us use Flux which changes the color of your computer monitor to brownish/reddish during the evening. It helps because blue light from monitors/iPads/TV’s/fluorescent lamps etc. delay the onset of sleep. It’s important not only important to change the monitor color but also switch over to incandescent bulb during the evening for the same reason. On the other hand wakefulness in the day is enhanced by bright of light, so having bright (blue light or natural light) is great to maintain alertness during the day.

Most humans have a period of day called the ‘wake maintenance zone’, this is the time around dusk when despite sleep build up we resist sleep, supposedly this was the period in the day when humans were under highest threat from animals during our stint on the savannah. We’ve evolved to be more watchful and alert around this period. This about a couple of hours around 6-8 PM . I’ve personally found this period to be the most productive (via RescueTime stats). This is also the time we fritter away either drinking in pubs or stuck in traffic instead of hacking productively at work.

Figuring out your chronotype is extremely important and plan your day around it, instead of around set schedules of  work at 9AM and home at 6PM. This is because your body clock controls when you are alert/hungry/sleepy rather than the time of the day. But it is really hard to manage different social times with internal time, this is where entrainment comes into play. Light is a really powerful zeitgeber for entrainment. For later chronotypes like me (most programmers?) it is useful to get enough sunlight in the day, so that it’s easier to sleep early. A quick heuristic: 2 hrs of sunlight in the day pulls back your normal sleep time by about 1 hr. Couple hours of cycling to work seems to do the business for me.

Temperature of the body plays a important role in sleep and we sleep faster (or better?). Body temperature drops as we sleep and a drop in temperature induces sleep. So it is harder to sleep after a vigorous run or walk, or a hot shower, because both increase your body temperature. I’ve personally found cold water shower to induce sleep. Also during the REM stage of sleep your body loses its ability to regulate body temperature (along with most muscles) and will follow the ambient temperature and hence it is important to sleep in a place which is not too cold or warm.


Internal Time : An excellent book on Chronotypes by a sleep researcher.

Dreamland:  On sleep/dreams etc. good fast read.

Flux Sleep research Page

Entrainment of human clock

Sleep wake rythms and cognition

Wake Maintenance

A course on sleep


The fallacy of “worst member of the band”

Lots of people talk about being in a group where people are smarter better than themselves. This probably is better, because you are assumed to be learning from these “smart” people all the time. Besides being too simplistic, it seems to me a fertile fallacy.

Do you remember all the members from Jimi Hendrix experience? which was dominated by Hendrix’s supreme mastery of the electric guitar. Or Cream, which was dominated by Clapton’s genius. But you probably remember all members of the Beatles, which was a much more balanced band. I posit that being the worst or even better member of the band is not good enough.

I am not saying seek out places where there are better people to work with, but that being the sole criteria is unfair for all the people involved and you take more from the “Circle of life” than you are giving back. This will never be sustainable.

Learning for me happens in 2 modes,

Working with people and picking up their tricks, opinions, ideas.

Working privately and following my own thought processes and experiences.

It may vary for different people, for me working privately, deliberately has been the main source of learning. This, I think because I can make mistakes and learn from them and figure out why and never repeat it again or figure out the situations to repeat it again leading to a deeper understanding. Rather than “best member of band” telling you to do certain things in the way he’s figured it. This leads to rapid learning but a much shallower understanding. (think Pair programming vs. Deliberate practice)

I say this with some experience, In the company where I work (Activesphere, for people not in the know), I went from worst member of the band to among the better ones and back to the bottom of the pile. ( I’d like to think not because I was going backwards, but because other people were making faster progress) This transition has taught me amazing lessons that might be subject for another post. The biggest one of course is that you need to be “best in the band” sometimes to figure out how to apply things you’ve learned. And eventually how to get back to the bottom by helping others get better than you. (If that makes any sense)

Bottomline, it seems to is to not worry in terms of worst/best member of the band but seek out what you want to do and what will help you get to learn better, rather than the rather mundane application of “Worst member of the band”


One of the most abused practice of XP has been Sustainable work week. Pretty much everybody agrees it is the right thing to do, but nobody actually does it (or that’s what I’ve seen)
The XP book talks about 40 hrs work week, but most people dub it as Sustainable work pace. This gives people the ability to set their work pace at 50 hrs a week or less or whatever, but it also acknowledges the fact that people are different, and one rule can’t fit all.

I ❤ programming, so I spend a lot of time writing and thinking of writing code, and making myself a better programmer.

IMHO, Writing more code, and spending more time writing code does not make you are better programmer. It is the practice of programming by trying different approaches to a problem and experimenting with tools (and adding to your toolkit or discarding them) that makes you better. The analogy being, driving to work and home does not make you a better driver.

So I definitely do lot more than 40 hrs a week, sometimes 60 hrs a week, not sleeping by the excitement of implementing a faster way of finding Recommendations, or different way of Visualizing an interesting data set, or some silly stupid hack that has no value. I like it that way. Is it sustainable? I’ve been doing this for a long time now and have no intention to reduce it. (I know what you are thinking!!! Yes I am a pretty slow). Is it ideal, heck no. But I believe (and I may be completely wrong on this one) I’ve developed workarounds to deal with the side effects of “Unsustainable pace”

What definitely helps is doing stuff that exerts the body, like running, cycling and playing squash with friends. Fitter people are anecdotally better equipped to deal with mental stresses of work and broken code. And yeah that constant dose of mindless Telugu movies with my wife.

One of the big things that helps me is taking longer breaks from work, like going out traveling for a few weeks or months. Invariably I have come back refreshed and with new and interesting ideas. This trick always works.

What’s your strategy to cope with excess time at work?