by adam_arthur · 4y ago · 0 comments
Code absolutely can be written in a self documenting way, just that most people don't structure their code like English/natural language. Also some languages have too much syntax bloat to be written effectively in a self documenting way.
I agree with the principle that some things are better expressed through documentation, such as motivations and higher level diagramming. But the average code base is so far from being self documenting, that the gap there should be closed first before moving on to external documentation.
External documentation creates a second source of truth that often falls out of sync with the code, so becomes a form of technical debt/maintenance burden.
The best way would be exporting docs from your codebase, and have all documentation related artifacts expressed alongside the code. Diagrams expressed in a programmatic DSL etc
I LOVE Golang's approach to this [1]:
- Documentation generation from code is built in to the language toolkit
- There is a standard for writing the comments so all of them look the same across every project
- It even supports code examples which are visible as a REPL in the generated docs
When people ask "what's so great about Go?". It's stuff like that which is hard to succinctly describe but makes a huge difference in overall quality of Go code in the wild.
Many of the Go features are only a win when the competition is C.
More to the point, just because some platforms provide equivalent functionality doesn’t make the GP wrong.
With some error handling code, for example, briefly commenting what conditions lead to what exceptions goes a long way.
But of course it depends on the context and what you're trying to do.
React/Vue is a good example. You have some Application component that has a set of sub components representing different regions of the page, which have their own subcomponents and so on.
Makes it very easy to dive in from top down and drop into lower level abstractions as needed.