You open a file you wrote yourself, you stare at a function you are sure you wrote, and for a few seconds you have no idea what it does — and you are the author.
I have published 42 posts on DEV now, and I still have that moment at least once a week. It is not a beginner problem. It is what happens when the person who wrote the code and the person reading it are the same person, just a few months apart.
Here is what I do now, before I change anything:
First, I read the callers, not the function. Who calls it, and what do they expect back? That usually tells me what the code was for faster than reading the code itself.
Second, I run it with a real input I remember, and I watch what comes out. One small print or log line, one input I understand, and the shape of the thing comes back to me before I touch a single line.
Third, I rename one thing and add one comment in plain words while I still understand it. Not a rewrite — just one honest name and one sentence about why it is there. I leave the code a little clearer than I found it, even if I change nothing else.
So now I am curious about your side of it:
- When did you last open your own old code and not recognize it at all — what was the code supposed to do, and how long did it take you to work it out?
- What is the first thing you do in that moment — do you read it top to bottom, run it, check the git history, or ask someone who was there?
- What is one small habit that has actually saved you the next time you came back to old code — a comment, a name, a test, or something else?
What I tried that didn't work: rewriting the whole file from scratch, because I thought I would remember the clever parts better the second time — I didn't, and I lost the edge cases the old code had quietly handled. And adding comments that just repeated what the code said, instead of saying why it was there.
No wrong answers. I am curious how much of your old code still feels like yours when you open it again.
Top comments (8)
This happens to me all the time, usually about three to six months after I wrote something in a hurry. My first move is the same as yours: find the callers and run it with a real input before I touch anything. The one habit that has saved me most is writing the comment in plain words while the reason is still fresh in my head, even if the code itself looks obvious at the time. Future me is always grateful for that one sentence.
Three to six months is exactly the window where it bites, fizan — long enough to forget the hurry you were in, recent enough that the code still feels like it should be yours. I like that your first move matches mine: find the callers, run it with a real input, and only then touch anything. And that one plain-words sentence while the reason is still fresh is the cheapest insurance there is; future you really is the one who cashes it in. Do you have a rule for what earns that sentence — the weird condition, the magic number — or do you write it whenever something feels even slightly non-obvious?
This hits often—usually 3–6 months later on something I shipped in a hurry.
First thing I do: find a caller and one real input, then run it. Reading the function top-to-bottom alone still leaves me guessing. Git blame helps only after I know what “broken” looks like.
Small habit that saves me next time: rename one unclear name and add one plain-English comment while the context is still loaded—exactly your step 3. If I leave without that, I’m teaching Future Me the same puzzle again.
That 3–6 month window is so real, Ameen — long enough to forget the context, recent enough to be sure it was you who wrote it. I love the git blame point: blame tells you when, but it can't tell you what "broken" looks like until you've already got a failing input in hand. And "teaching Future Me the same puzzle again" is the perfect way to put it — that rename-and-comment habit is basically leaving a note for the person you'll be in six months. When you do run it with that one real input, do you usually find the answer in the output itself, or does watching it run just remind you what the function was supposed to do in the first place?
I look for the commit that introduced the odd condition, then the issue or test attached to it. The function can tell me what it does; the commit sometimes tells me which tempting simplification would bring the bug back. That is the bit I want in the comment when I finally understand it again.
That is a sharper move than just reading the code, Andrei — the function tells you what it does, but the commit tells you why the odd condition is there at all. Tracing it back to the issue or test behind it is the difference between understanding the code and understanding the decision, and that tempting simplification you mention is exactly the trap: the code looks cleaner without it, right up until the bug comes back. Writing that bit into the comment once you understand it again is the part I want to steal. When you find the commit, does the issue usually make the reason obvious, or do you often have to piece it together from the test as well?
I think I can always tell what my old code does. But the main question here is the quality of that code — it can be terrible. So I get a little embarrassed and quickly close the old project.
That distinction is a good one, Roman — knowing what the code does and being proud of how it does it are two very different things. And honestly, closing the project quickly is such a relatable move. I have done the same when the code worked but the structure made me wince a little. Do you ever go back and tidy up one of those embarrassing spots once the sting fades, or do you prefer to leave it as a snapshot of how you coded back then?