I figured I’d go a little off topic today compared to my past posts and talk about my experience with sleep and coding. I’m working on building a small, but relatively complex, website at my current job. The goal is to develop an internal tool that specific teams will use to plan work. Throughout this journey, I’ve had many days where I’ve come to work very tired, due to having to wake up early for my job and not going to bed before 10pm. On those days, I’ll try to write code. Not only is it difficult and sluggish, but I end up looking and my code the next day and realizing I wrote complete crap. This forces me to have to redo what I just spent a whole day doing. If I’m not sleep deprived while redoing my work, I can get it done in a quarter of the time.
This leads me into thinking about a similar scenario: coding while stressed. I feel like this is almost worse. I find that when I’m stressed while coding, particularly if I’m in a rush to finish a section of code, I end up writing code that is far from optimal. I could go back and fix it, but if I’m in a rush I tend to forget that I wrote crappy code and move on. Or I just keep coding because I want to get things done faster. Then, when it comes time to add a new feature, I have to refactor and rebuild big portions of what I had previously built in order to optimize things. When I’m not stressed, I take the time to research and develop an optimal solution to whatever it is I’m building, which saves time in the long run.
I believe one of the key realizations I’ve had while building projects pertains to the idea of “technical debt” (I think that’s what they called it in Software Engineering II). This is where you choose a fast and easy solution for the sake of time or money instead of developing an optimal one. Then, over time, the result is that you have created a giant mess that is time consuming to debug, fix, and add features to.
The big idea here is that coding while sleep deprived or overly stressed can lead to increased technical debt, which leads to more stress and sleep deprivation due to having to fix and refactor messy code. Don’t be like me. Get enough rest and take a minute to destress before building something.
Cat pic attached: