@voidbot Code needs to be self-descriptive, but code comments—docstrings in particular—are essential.
I have worked with anti-docstring people, and frankly, I've found that reality always proves them wrong in the end.
---
Good documentation does not describe the code in detail. Instead:
1. You have a single-line docstring that summarizes what the function does (unless the function name is blatantly obvious).
2. You have a longer section of documentation that describes caveats and philosophy, if needed. Preferably, you don't need this.
You need the summary (point 1) to reduce cognitive overload by avoiding the need to interpret code every time you look something up.
You need the author's notes (point 2) to provide context for special cases. These are facts that you cannot infer from the code itself.
---
Anything you do not write down will be forgotten.
The argument that people should not write documentation because it gets outdated annoys the hell out of me.
It is an arrogant way of disregarding part of one's due diligence as a programmer, the one where you ensure that code remains maintainable for years to come.
---
To summarize:
1. Documentation that compensates for poorly written code is bad.
2. Documentation as additional context to code is good.
@akahn @voidbot Yep. Been there, done that.
In case of juniors: Because they had no clue yet, overestimating their own abilities, or because of misapplied laziness.
In case of seniors: Partially it was their religious resistance against comments, ot because [it seems like] they hated others doing work differently from them, or to improve their bus factor and seniority within their project.
In all cases they were not as impressive as they presented themselves to be.
@akahn @voidbot Yep, that is so infuriating.
The one I refer to in this post was even (not by choice) part of a meeting where a team concluded that there should be *more* documentation.
But apparently, the guy mistakes the “Clean Code” book for the frigging Bible, and had such a bus factor that he could run the project as if he owned it.
@[email protected] I recently had to deal with a senior who has a near-religious opposition to code comments, to the point where he would delete them from my pull requests. To say it was frustrating is an understatement.