frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

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

13•siddhibansal9•13h ago
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.

Comments

xupybd•6h ago
You often can't. Also don't assume the original why was correct. Instead learn the problem domain so well that you can make your own judgements.
mierz00•1h ago
This also goes the other way too, you don’t assume the original is incorrect.

I see this a lot with developers who come in and start to criticise before understanding.

There is always a reason for why something is as it is, and it’s unlikely that the people before you were just idiots.

taklimakan•6h 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.

bni•5h ago
If it's architecture you need to time travel back to the time and the circumstances, requirements and priorities around that time. Good luck.

When it comes to code, run the unit tests.

treadmill•5h ago
Read the BDD style acceptance tests that were written during development. This is the one chance you get to preserve that knowledge when it fresh and correct. Asking someone three years later (even the original dev) is no substitute. Oh, and you can also run the tests to ensure correctnes.
heenrik•5h ago
Tangential: Peter Naur has something to say about this in his "Programming as Theory Building" paper.

TL;DR: You have to reimplement the application or features to understand the "why" regarding technical decisions.

abstractspoon•5h ago
I use 'git blame' to help me find the commit and the branch, and then infer the rest
Moldoteck•4h ago
Git blame if I'm lucky the commit to be documented
wonger_•4h ago
Do any teams keep a decision log for these sorts of scenarios? Especially when a comment is not enough, e.g. architecture or dependency choice?
SomeUserName432•4h ago
> Where do you look first?

Git commit will generally explain why it was done. The task it references may or may not explain the decision process that lead to it. Usually not.

It's rarely related to code, more often a business decision due to some obscure reason/desire which may or may not provide any actual value.

palmotea•3h ago
> Git commit will generally explain why it was done.

Sometimes, not generally. A lot of people are bad at commit messages, and commits migrated from older tools may be unusably terse because those tools didn't support multi-line commit messages well.

strogonoff•3h ago
Taking to the person who did it (who wrote the code, who reviewed it, who gave the specification, who worked anywhere near at that time) is the best way to understand why it was done.
pella•3h 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•2h 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.

alexhans•3h ago
The fact that you have to dig through things to find it should give you good hints in what is desired for your own code. You want your WHY comments very contextual and findable.

1. Either literally as a comment in the code. Immediately findable

2. As a description in the commit (easy to find with git blame).

3. As a comment in the Code Review/Pull Request system. This works for very stable things but is more brittle than the other ones. Usually exposes the discussion among parties but the outcome of that discussion should probably be in 1. And 2.

Another benefit of keeping comments in the context of where they happen is that you'll actually remember to update them. Otherwise, they're duplication (code smell) and introduce a risk of divergence.

That's why WYSIWYG standalone word docs or similar for design or manually written wikis are so dangerous for code that lives and keeps changing. The thing that keeps teams tidy is often single sources of truth where you can generate/render other things easily.

---

Reading tests or talking to someone is possible but if you had to do that for everything you might waste a lot of time so while it can be extremely beneficial I don't consider it my thought process.

solaris2007•3h ago
If you aren't on a high talent density team comprised of people you have learned you can trust, assume the worst because far too often the original author didn't know why either.
hahahahhaah•3h ago
Search slack. Find chesterton there.

Otherwise cross reference ticket.

Otherwise search docs.

Otherwise ask teammates.

Otherwise don't change it.

If you have to change it have a careful rollback / DR plan.

krupers•2h ago
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 programmer still worked in the same department, and he actually remembered some of the choices he made. Other than that, it was a matter of remaking the same mistakes and figuring out the "why's" the hard way.
ahoka•1h ago
Just write comments?
gghhjnuhbb•25m ago
Ask the person who wrote it. If they are gone, think very hard for a few fays about the problem and the thought space they were in. If all else fails, change the code and watch what bugs percolate.

Edit: typo

austin-cheney•25m 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 a 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 business 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.

How do I make $10k (What are you guys doing?)

2•b_mutea•23m ago•5 comments

Ask HN: What AI feature looked in demos and failed in real usage? Why?

2•kajolshah_bt•37m ago•2 comments

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

13•siddhibansal9•13h ago•21 comments

Ask HN: Does DDG no longer honor "site:" prefix?

15•everybodyknows•10h ago•5 comments

Tell HN: Cursor agent force-pushed despite explicit "ask for permission" rules

6•xinbenlv•6h ago•4 comments

Ask HN: Do you have any evidence that agentic coding works?

441•terabytest•2d ago•442 comments

Ask HN: Best practice securing secrets on local machines working with agents?

8•xinbenlv•22h ago•11 comments

Tell HN: 2 years building a kids audio app as a solo dev – lessons learned

133•oliverjanssen•1d ago•75 comments

Ask HN: Is Claude Down for You?

25•philip1209•13h ago•19 comments

Ask HN: Why are so many rolling out their own AI/LLM agent sandboxing solution?

29•ATechGuy•2d ago•11 comments

From Sketch to Masterpiece: Understanding Stable Diffusion Img2Img

2•bozhou•6h ago•0 comments

Ask HN: How do you authorize AI agent actions in production?

5•naolbeyene•21h ago•4 comments

Ask HN: What is your opinion on non-mainstream mobile OS options (e.g. /e/OS)?

5•sendes•18h ago•3 comments

Ask HN: Have you managed to switch to Bluesky for tech people?

9•fuegoio•13h ago•9 comments

Ask HN: What's the best virtual Linux desktop experience on macOS for devs?

7•darkteflon•13h ago•4 comments

Ask HN: COBOL devs, how are AI coding affecting your work?

168•zkid18•3d ago•183 comments

Ask HN: Modern test automation software (Python/Go/TS)?

7•rajkumar14•15h ago•3 comments

Ask HN: How do you verify cron jobs did what they were supposed to?

6•BlackPearl02•1d ago•9 comments

Tell HN: Drowning in information but still missing everything

9•akhil08agrawal•1d ago•7 comments

Ask HN: Revive a mostly dead Discord server

20•movedx•2d ago•28 comments

Tell HN: We have not yet discovered the rules of vibe coding

2•0xbadcafebee•10h ago•0 comments

Ask HN: Industrial smart glasses with online / offline capabilities?

3•aureliusm•22h ago•0 comments

Ask HN: Anyone doing production image editing with image models? How?

4•geooff_•19h ago•0 comments

Ask HN: Does "Zapier for payment automation" exist?

8•PL_Venard•1d ago•12 comments

Ask HN: Is there any good open source model with reliable agentic capabilities?

4•baalimago•1d ago•0 comments

Ask HN: Unusual Network Filter

4•gman21•23h ago•0 comments

Tell HN: Claude session limits getting small

23•pragmaticalien8•1d ago•15 comments

Ask HN: Claude Down?

3•emschwartz•13h ago•2 comments

Ask HN: Which common map projections make Greenland look smaller?

18•jimnotgym•2d ago•17 comments

Tell HN: Avoid Cerebras if you are a founder

34•remusomega•1d ago•14 comments