Can't fall asleep? Code instead?

A (Productive?) Sleepless Night

I had the recent misfortune of an unintentional sleepless night. But I as I toss and turned in my bed, almost wide awake at 3AM, dreading the impending day of meetings, gym sessions and running clubs. Something amazing happened…

“Let go of your earthly tethers” and give up sleep…

I just gave up on sleeping. Now this isn’t something that’s easy for me to do. I value my sleep and my sleep schedule to the point of stubborness. I despise any event that starts later than 9pm, I’ll turn down invitations to parties citing my sleep schedule and I’ll do everything in my power to “stay regular”.
But I gave it up. Mainly because I had no other choice as I had been unable to fall asleep for almost two hours at this point, largely because I had committed the cardinal sin of napping that day and it was clear I was paying the price tonight.

So I did what any normal “software engineer* would do… I turned on my computer instead. I did this almost mechanically, because I didn’t know what I could possibly accomplish in this daze. Maybe some youtube videos to pass the time, check and address some emails (you know mindless stuff), but eventually I couldn’t resist my engrained muscle memory and ended up opening our organizations Github repository to look at some code 🤓.

Laser Focus

I scrolled randomly and aimlessly through my teams PRs, sometimes having the urge to leave a comment but resistanting valiantly because I didn’t want to leave any evidence of my insanity by doing a PR review at 3AM on a Friday.
Almost by concidence I stumbled on a problem code path that had been bothering my team for weeks/months but was one of those issues that would never get prioritized because it wasn’t a critical issue or feature.

Honestly, I’m not quite sure what happened next, because I honed in on this problem with extreme laser focus. Focus that I handn’t been able to muster for this problem in a long time [1].
I ended up programming for 3 straight hours in a kind of FLOW that I hadn’t been in for a very long time. It felt really good. I ended up refactoring the code and prototyping a solution and a way forward. I’ll probably have to review my PR after proper night’s sleep; because who knows what kind of bugs I’ve introduced in my sleep adled stupor. But at 8am I was in a very good state of mind, not at all depressed or frustrated about my lack of sleep even though I was acutely aware of my fatigue and my growing in ability to keep my eyes (👁️) open.

Why even bother sleeping?

Now I’m not recommending that you should pre-maturely give up on sleeping and code instead. That’s obviously unhealthy, especially in the long run. But sometimes life gives you lemons in the form of sleep deprivation, and instead of bemoaning your fate you can try to take advantage of the uninterrupted working time.

No one will bother you at 3AM

Because remember, there won’t be any distracting messages, meetings or other events that can distract you.
It’s just you and your own thoughts, and maybe your computer screen if your anything like me.

Footnotes

  • [1] Think in my sleep deprived state I only had the mental capacity to focus on one thing. And one thing only.