Open matttproud opened 2 months ago
Packages can already have a long top-level doc comment (rendered as "Overview") with detailed usage introduction and examples, see the testing package as an example.
@fzipp That's true and arguably omitted from the top-comment. But I think a guided tour is still a qualitatively different and more helpful form of documentation, especially when considering that there might be multiple scenarios.
My assumption is that if package maintainers aren't fully utilizing the potential of the available space already, they won't use additional space either. The real issue is that many developers prefer programming over writing documentation.
There are several cross-cutting considerations here:
Step 1. Open drawer
, Step 2. Pull out carrot peeler
, etc) with the amount of structuring required, potential length, and the number of different journeys a package could have, the top-level documentation block for a package could get very unwieldy. Some of existing standard library packages do have long ones, but I can think of a couple of foundational business logic libraries in my workplace that are not too complicated but that would easily add multiple hundreds of lines to a hypothetical package's doc.go
file. The package's central documentation is fine for some things, but not others. Nevertheless, I fully agree that it is underutilized.We need a multi-pronged solution to documentation. Developers who want do the right thing (there are many of us who do) simply do not have the means.
I use the example docs extensively in my open source projects. If I could build a programmatically tested tour with the Go tool, I would probably do that instead of using a README because the README can get out of sync pretty easily.
Proposal Details
Background
Go packages can have two distinct forms of documentation:
Comments anchored to identifiers as described by Godoc: documenting Go code and Go Doc Comments.
Runnable (API) examples as described by Testable Examples in Go
Both of these are rendered in godoc and pkgsite.
These two forms of documentation serve somewhat overlapping/disjoint purposes:
Problem
In this public discussion, it became clear that a type of documentation is missing for users: step-by-step tutorials or material that focuses on an end-to-end developer journey. This led to a thought about how we could fix this gap in a nice Go-like way.
Proposal
What if we expanded the documentation servers to enable users to create their own API tours à la A Tour of Go? A package could have multiple tours to demonstrate the journeys.
Imagine a hypothetical Go module at
github.com/matttproud/rot13
that follows a directory structure like this:We could have a directory structure like this:
Then the respective documentation servers would have some sort of internal support to run tours (e.g., use what binary tour uses). When viewing the respective package in the viewer, the table of contents for the package would also include a heading that lists sub-elements of available tours (tracer shot):
This has the advantage of keeping the documentation for extended workflows adjacent to the code so that it can be always fresh.
Perhaps this could even be extended to support the present tool, too.
Rejected Alternatives
There is technically a third form available: the blog post (e.g., Go Concurrency Patterns: Context), but …