back to Writing Market Image

Rest is Key to Good Quality Code

Sleep is for the intelligent not the weak.

Jul 10, 2020

I’ve been mulling on this topic a bit lately as I’ve been prone to jumping on the bandwagon of the late nights strong coffee and even stronger Scotch. If you follow the school of thought that coding is an art form then you may feel like it makes sense to drain yourself to your root, and write code freely in the dark of night while your mind zones in. Though I have read there are some benefits to this approach I think the negatives far outweigh them.

The Zone

I have had many late nights where coding late into the evening has helped me stumble into that mystical zone. The place where all code just makes sense and the big picture and small picture combine into an elegant string of variables and methods. In short, I’ve been in that state where my brain (yours does this too) is beginning to shut down its sensory perceptions. Ironically, this create a sort of hyper-focused state but it’s mostly because your brain is unable to process anything else. This is the state where even if you get messages or there are issues you’re so deep its a challenge to get out of the focus. Though I have enjoyed times of reaching this psudo-nirvana, I don’t think its something to be sought after. My best code results are often from working in short bursts of focus. These are moments where I’m able to read thoroughly, make notes and then leave the code for a few hours to settle in my mind, think of it as a buffer management system.

The Aftermath

We often celebrate the late work sessions and multiple day burn outs which result in code we’re proud of. We will torture ourselves but just enough that we can still enjoy the outcome. However, we often neglect the fact that late work nights, burn out sessions, over caffeination and cheap carbohydrates result in long term detriment. Diving into one of these work sessions feels like it will only be a day or so to recover but it can have long term consequences. There is the real fact that sleep deprivation has severe health consequences, and there is a sad irony that the code you may be writing in that late night session may end up refactored completely in less than a year. Does that actually make it worth deteriorating you brain over it? We often also neglect the impact that it has on our social lives and skills. We’re often more edgy and short with co-workers, which results in poorer quality code revisions and focus.

I myself if I’m tired enough will take naps on my office floor. These may be fifteen minute naps or even thirty minutes but I’m always better off doing this rather than making another pot of coffee or chugging back energy drinks. Our minds are always working and processing even in sleep. Personally, I’d much rather let my brain process a complex problem in sleep than while I’m sitting in the dark with bags drooping under my eyes as empty cans of Red Bull lay across my office floor.