The Error might sit in the chair
We write code for humans, not for the computer itself.
Programming is the craft where we teach computers how to perform a sequence of actions. We can talk about what constitutes good code and how to write it. But after all, many data scientists tend to work step by step, and then edit the code after they established that it works.
Thanks for reading ds-econ! Subscribe for free to receive new posts and support my work.
I noticed that there are some quirks, we as humans have while writing our code.
Long computation times make us nervous. We start to think that the code is “doing something wrong”, for a mysterious reason, or we suspect that our laptop has crashed. We are often fine with waiting for a minute or two, but occasionally, our code takes hours to run. Can you feel the urge to press Stop, or to force-quit your VS Code / R Studio / Jupyter, after your code has been running for two hours?
Can it really run for so long? Let’s wait for one more minute and then a little more. It still hasn’t finished, something has to be wrong here, right?
Every so often, we write code in a way, that makes it humanly impossible to find its flaws. After programming a script of several hundred lines, we tell ourselves that this must be a big, complex, project. However, when we need to scroll for 30 seconds to reach the end of our script, how will we ever find the wrong data-type in line 204, when it only causes an error in line 397? How can we see the mistake, if it doesn’t even fit on the screen?
Yes, you are writing code for a computer to do things — But is your computer really the audience of your program? Aren’t you really writing the code for your future-self / your colleagues / the world?
How do we remind ourselves that
df_output_monthly_2023_2, the data frame in line 32, was just to take a look at the data, and not relevant for the computation, when we come back to our project after a long weekend?
Consider making your code more human.
Think about documentation, warning messages, or adding progress-bars to your for-loops, to show the human in front of the machine that her computer is still alive.
Like writers, or carpenters, programmers create something for humans.