Readit News logoReadit News
Posted by u/siddhibansal9 19 days ago
Ask HN: How do you find the "why" behind old code decisions?
Curious how teams actually handle this in practice.

When you’re modifying existing code and need to understand why a decision was made:

Where do you look first?

How often do you fail to find a clear answer?

What do you do when the original author is gone?

I’ve been running into this more often lately --digging through PRs, Slack threads, and half-written docs just to piece together context, and I’m wondering how common this really is across teams.

sloped · 19 days ago
The honest answer is you probably won't find it. Historical documentation is hard, it is the first "features" cut when teams are scrambling to meet a deadline. There is no malice in this, it's just something that the end user doesn't need or see so when shit hits the fan, it get skipped.

Commit logs, slack/email/etc, documentation silos, or issue trackers are your best bet, other than actually being able to talk to the author(s) of the code.

But in general, the decision was made because in the time the developer had to implement the feature or fix, this was the best solution they could come up with. Hopefully if there were clear tradeoffs, there is some comment as to what they might have done with more time. Likely though they were rushed, told their team they wanted to go back and fix this, and then were ushered into a new project the second this one stabilized.

I think gghhjnuhbb has the best alternative to finding actual documentation and that is sitting and putting yourself in their headspace. That can sometimes lead to insights you might have missed.

SAI_Peregrinus · 18 days ago
This is why I hate the common pushback against "TODO:" comments. They're an extremely fast way to leave a trail of what alternative path would have been taken had there been more time. They're part of the code, so they don't get caught up in a "backlog grooming" the way a Jira ticket will, and don't break flow the way switching to Jira will.
birthdaywizard · 18 days ago
We call this "code archeology" at my company.

We're more diligent about ticket descriptions these days, but we weren't always. Obviously the best is to be able to to talk to people, followed by documentation, either explicit documentation or on the ticket itself .

After that it can be useful to look at all commits that were related to the change itself. You can often piece together why something was done from looking at how the changes happened as whole, or even which parts were rewritten as requirements changed.

Another option is to talk to people in your org closer to clients. Support or client managers can sometimes have a better idea of how features are actually used, meant to be used, or what parts are more valuable than product or engineering will, especially if they're revisiting a feature for the first time in many years.

But yeah, often you can't. You're best bet then is to make sure you really understand the feature look at it with fresh eyes. Say "Well this is how it DOES behave, how do we want it to behave from here?" Actually talking to clients can be helpful here if any of them are willing to talk to you. In enterprise software, you can probably find a client who wants to shape the direction of the feature and has some strong thoughts.

FrostViper8 · 19 days ago
I look through commit messages and try to link it up to a Jira ticket and piece it together. Often the original developer has left, or if they are still present doesn't remember why.

Most of the time I don't know why something was done a particular way .

nuc1e0n · 18 days ago
In the corporate environments I've worked in it is often company policy that all commits to source code control should have messages that start with reference codes to the coresponding ticket in the issue tracker (often jira). This how I look up the whys and wherefores of code changes.
FrostViper8 · 18 days ago
A lot of places just don't do this. Unless there is a threat of a written warning some devs will do the bare minimum. I currently work with a guy that sometimes doesn't even run the code he checks in, I doubt he really knows how to code and everything is basically AI, management won't do anything and it the only remote job I could get. Another guy I work with won't do basic CSS fixes to things that are broken, so I cleaned up the login page for the site he is responsible for.
pella · 19 days ago
retroactively - create Lightweight Architecture Decision Records (ADRs) by reconstructing key decisions from the available sources, then make it a habit to maintain them for all future changes.

- https://github.com/peter-evans/lightweight-architecture-deci...

- https://adr.github.io/

- https://www.thoughtworks.com/radar/techniques/lightweight-ar...

digikata · 19 days ago
The easiest is to add short info in comments, and longer info in some sort of document and reference the doc in comments.

Lightweight ADRs are a good recommendation. I've put similar practices into place with teams I've worked with. Though I prefer to use the term "Technical Memo", of which some contain Architectural Decisions. Retroactive documentation is a little misaligned with the term ADR, in that it isn't really making any sort of decision. I've found the term ADR sometimes makes some team members hesitant to record the information because of that kind of misalignment.

As for retroactively discovering why, code archeology skills in the form of git blame and log, and general search skills are very helpful.

ivoryweb · 18 days ago
I’ve run into this a lot. In my experience the “why” usually isn’t in the code or the docs—it’s in the constraints that existed at the time (latency, incidents, org structure, missing tooling). What helped me was reconstructing the failure modes they were guarding against, not the feature intent. Once you see what they were afraid of breaking, the decisions make more sense—even if they’re obsolete now.
tmsh · 19 days ago
It’s a reason to push one’s teams to have conventions: (1) all commit messages have an issue number (2) all issues have acceptance criteria or link to issues that do.

Then the answer is just one prompt away… (I wish our team was more committed to 2 - will push for it more in the future). Having acceptance criteria in stories linked at the start of each sprint is so important though I think for alignment of work.

austin-cheney · 19 days ago
The answer to why is almost always because that is the limit of talent available to the organization at the time with the given technology options available. Its really that simple.

In some cases there are many options and great talent is readily working on the problem for the given organization. Its nice to have options, but this is an exceedingly rare scenario. For example there are tons of options available today, but from reading HN job posts it looks like the answer is still a CRUD app that does some SAAS solution with React, AI, and Python. I could guess that and be right more than 60% of the time, which is extraordinary considering these businesses have thousands of technology combinations and unlimited ideas to pick from. Its all about the talent available, but when I say talent I just mean people because when you are that restricted it isn't very talented.

taklimakan · 19 days ago
It’s either documented or it’s not. When I modify code in a way that isn’t immediately obvious by looking at the code itself plus the immediate surroundings, I write a two-or three-lines code comment. It takes me ten seconds and does a big favor to my future self. I fail to understand why this isn’t standard procedure.

To actually answer your question, do a git blame, check the commit messages and anything linked in commit messages. Do some search in the company’s internal knowledge base, architecture documents, specs, whatever you have available. Even if you don’t find a direct answer, understanding some more context might eventually lead to one.

If you have no documentation at all anywhere, then you have to analyze the code yourself. It’s part of your job. When you’re done be sure to document your findings.