I read my own code from two years ago, here's what embarrassed me
Last week I needed to pull a small utility out of an old project, something I built during my first real attempt at a side product. I opened the repo expecting a quick copy paste job. Instead I spent two hours reading my own code from two years ago like it belonged to a stranger, and honestly, some of it did. Here's what actually embarrassed me, in the order I found it. The function that did five…
Last week, the author needed to extract a small utility from an old project they had worked on during their first side product attempt. Upon opening the repository, they spent two hours reading their own code as if it belonged to someone else, and found several instances that embarrassed them. The author presents these embarrassing moments in the order they were found.
First, they discovered a function called `validateUser` that performed multiple tasks - validating the user, hitting the database twice, sending an email, writing a log entry, and silently mutating an object passed in from three layers up. None of these actions were mentioned in the function name or comments, as past self believed comments were for others.
Next, they came across a convoluted `processOrder` function with twelve arguments, no types, and no clear naming conventions. The author struggled to understand the purpose of `flag1` and `flag2`, having to open multiple call sites to decipher their usage. They attributed this to the function's gradual accumulation of features, each added to handle a specific edge case.
The author then encountered a stale comment `// only runs once` alongside a line `setInterval(checkStatus, 5000)`, which ran every five seconds indefinitely. They questioned whether this comment was initially a false hope or a true statement that remained unchanged despite code modifications. Lastly, they found an empty catch block that silently swallowed errors without logging or rethrowing, erasing any evidence of failed database saves during its operation in production.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.