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 (3)
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 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.