Live data from Hacker News

Ask HN: How do you find the "why" behind old code decisions?

news.ycombinator.com

31–40 of 44 posts

Re: Ask HN: How do you find the "why" behind old code decisions?

#31

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 .

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.

Re: Ask HN: How do you find the "why" behind old code decisions?

#32
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.

Re: Ask HN: How do you find the "why" behind old code decisions?

#33
Sometimes the why is discovered when you try to change the code to what you think it should be and see it fall down in some cases you didn't anticipate or some other system is affected. It's often really hard to find out the why but either it will become clear at some point when the code is refactored or it will be irrelevant.

Re: Ask HN: How do you find the "why" behind old code decisions?

#34
The question you're actually trying to answer is unlikely to be "why is this the way that it is" and more likely to be "if I make this change, will I break anything". So just don't worry about it: make your change, open a PR, socialize it as widely as is practical, and if nobody stops you, merge it and move on. In many cases, the original "why" doesn't matter anymore. If it does, having a concrete change to look at and critique helps move the discussion along (and prevents getting trapped in hypotheticals - they can see exactly what you're trying to do if they have a PR in front of them).

Re: Ask HN: How do you find the "why" behind old code decisions?

#35
post #18

This thread makes me think of when I was refactoring a COBOL application when I just started my SWE career in 2016/2017. The original program was from 1989 and things like git blame, ticket systems etc. wasn't there. There was rudimentary version control, but that didn't go back to far, and also surprisingly there was some documentation. But the major thing that helped me answer the "why's" was that the original prog…

How did you start your SWE career in 2016/2017 refactoring a COBOL application??? Sounds like a fun story!

Re: Ask HN: How do you find the "why" behind old code decisions?

#36
Its what commit messages are for!

The diff tells the 'what' - no point in writing 'added method bob()'

The message tells the why.

You can bet that over time, the jiras, the issues and the confluence, slack, o365, will all have been deleted, "upgraded" or whatever, and all you have is what's in the repo.

Using in-repo ADR, and in-repo 'what's missing, what's next' files are also useful, because they co-evolve with the code.

Re: Ask HN: How do you find the "why" behind old code decisions?

#37
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.

Re: Ask HN: How do you find the "why" behind old code decisions?

#38
post #26

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 t…

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.

Re: Ask HN: How do you find the "why" behind old code decisions?

#39
When I used to work at my previous job, it was required that we have detailed PR descriptions (we had a template) and our commit messages were meant to be concise/clear.

So in practice it was usually not too bad. Git blame on any line could point me to the PR and any associated ticket.

You just need to have some discipline among the team because there would be slackers who didn’t want to take an extra 5 min. But you know. You weed them out.

Re: Ask HN: How do you find the "why" behind old code decisions?

#40
Really depends on your engineering processes, but this is why you want to enforce good processes.

- Every change beyond the most insignificant package bump should be ticketed, and specifically tickets should document the business why.

- Every PR should include a high-level description of the change, and should document any technical whys. It should also link to the ticket.

- Code comments should be used where appropriate to document code-level whys and hows.

- For significant architectural changes ADRs should written up to document why the architectural change was made.

Failure for your team to do this results in the problem you're experiencing now.

Post reply on HN