Ask HN: How do you find the "why" behind old code decisions?
11–20 of 44 posts
Re: Ask HN: How do you find the "why" behind old code decisions?
#12- https://github.com/peter-evans/lightweight-architecture-deci...
- https://www.thoughtworks.com/radar/techniques/lightweight-ar...
Re: Ask HN: How do you find the "why" behind old code decisions?
#131. 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.
Re: Ask HN: How do you find the "why" behind old code decisions?
#14> 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.
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.
Re: Ask HN: How do you find the "why" behind old code decisions?
#15Re: Ask HN: How do you find the "why" behind old code decisions?
#16Otherwise 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.
Re: Ask HN: How do you find the "why" behind old code decisions?
#17retroactively - 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...
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.
Re: Ask HN: How do you find the "why" behind old code decisions?
#18Re: Ask HN: How do you find the "why" behind old code decisions?
#19You 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.
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.