The Case for Documenting Code
I regularly read articles from other devs â learning about everything from nitty gritty technical details to big-picture organizational strategies. This week, I read an article advocating against documenting code, prompting me to reflect on its importance in maintaining code quality and fostering effective collaboration.
I love reading Ryan Petermanâs work from The Developing Dev. Peterman writes concisely â within one minute of reading, Iâve learned something new, and Iâm done within five. Iâd highly recommend his work.
Itâs rare that I read one of his articles and find myself in strong disagreement. This week was a bit different, though. I opened my inbox on Friday morning and was greeted by a bold headline: The Case Against Documenting Code.
In your next few minutes, if youâll let me have them, Iâll explain why documenting code is essential for successful software development.
The case for documenting code
Defining âdocumenting codeâ:
- Limited inline commentary, only to explain highly complex or surprising logic.
- Moderate function / class / module level explanations that are concise and informative.
- Significant API documentation, if appropriate (especially if this is a public API).
Why you should document your code
Documenting your code in the aforementioned manner does the following:
- Lowers the barrier to entry for new contributors, thus boosting productivity across a team in the long run.
- Establishes a positive reputation for your tool â be that internal (your team) or external (customers, general public, etc).
- Helps to minimize scar tissue by encouraging more thoughtful design for edge cases â the more complex a design, the harder it is to document, and thus itâs less attractive as a final choice.
Some direct rebuttals
Peterman makes the following claims against documenting code. Iâll follow them with my refutations.
No one actually wants documentation. What they want is the ability to get things done. Sometimes documentation helps us move faster. But that often isnât the case.
I think folks do want documentation â engaging with it is one of the easiest ways to get over a learning curve. In order to get things done, you need to get over at least some of that sigmoidal beast.
Documentation doesnât necessarily make your development faster, but it certainly accelerates that of others.
Since software engineering is collaborative, youâd need everyone to remember to update the documentation.
Right. My rebuttal here is simple â enforce updates. Ensuring quality across a team necessitates enforced standards, both in both the technical and process spheres.
That new branch of information is only useful if people read it. Since itâs separate from the code, itâs easy to get lost somewhere.
Aha! Why are your docs separate from the code? That does make things challenging. Integrate the docs easily with tools like mkdocs to ensure documentation is both read and regularly updated.
Positive reputation in the community, tools should be easy to use â people just want to get stuff done.
Some reasonable counterarguments
In all fairness, here are a few ideas that I think serve as logical rebuttals to my general claims above.
Code should be clean enough that internal documentation demands are low.
If a project requires an abundance of internal (worst of all, inline) documentation, itâs the organization of the code that needs reconsidering, not the docs.
And, a few from Peterman:
Iâm hopeful that one day, you could chat with the codebase and get up-to-date, simple explanations. Given the improvements weâre seeing in LLMs, I donât think this is far off.
I do think thereâs room to have LLMs assist significantly in writing and interpreting docs. Though, Iâd argue we should retain readable documentation, and not just resort solely to LLM interpretations of the codebase.
Engineers need to think about the ROI of everything they do. Documentation is no exception.
I agree fully with this statement. I just happen to be of the opinion that ROI for documentation has the potential to be quite high, if you do it right, and consistently enforce improvements and updates.
Conclusion
Itâs simple: docs are remarkably important, and too often neglected.
I write this article as an open source maintainer (for Pydantic, the most popular data validation tool for Python). The open source would crumble without documentation. Needless to say, Iâm quite the fan ð.
If you liked this post, please consider sharing it with others. Thanks for reading along!