Skip to main content

Sphinx supplement

Once upon a time, i was in a team led by a developer who was devoted to introducing modern standards. he didn't have much experience, so i think this devotion was essentially a cloaking device. though we didn't generate documentation, most pull requests elicited a request for a docstring change.

my first post about Holistic Development focused on logging. this one is about generated documentation. though software developers habitually read code, generated documentation can become their primary source of information because it's easier to read. it also assures product owners that features are addressed, and that the design is orderly.

Documentation review

a docstring is just a comment until documentation is generated. at that point, evaluation of docstring quality should be based on the generated documentation. sometimes a word should be formatted differently; sometimes it should be a link. in other words, a docstring's contribution to the generated documentation is more/less appropriate depending on its context.

Documentation conventions

PEP 257 is obsolete because it predates type hints. adopt sensible conventions, enforce them strictly, and configure code quality tools accordingly.

i think generated documentation should avoid implementation details. doing this makes information more accessible for product owners and clients. limiting the scope of this documentation also eliminates protracted discussion about docstring quality. describing interfaces and other externally visible features is so important, we should be reluctant to dilute this information. most importantly, there isn't enough time.

in this approach, private definitions should not have docstrings. thus, exceptions raised by private methods should be described by the corresponding public methods. more generally, emphasizing documentation quality influences visibility. a class/method that should not contribute to documentation should be private!

Sphinx usage

a language implicitly defines conventions, and some of these are de facto standards. for example, repr("spam") returns a string containing single quotation marks. not surprisingly, Python's documentation consistently uses single quotation marks in its examples. Black is better than chaos, but it's a bit boorish.

though Sphinx is the standard documentation generator for Python, i once used Doxygen to generate documentation for a Python SDK. this SDK was delivered with a PHP SDK for the same service, and i wanted to make them as similar as possible. one could flip between corresponding documentation pages by editing the language name in the URL, because the packages used the same namespace, class, and method names.

those documentation pages were a little old-fashioned, but they were neat enough and included inheritance diagrams generated by graphviz. though it may have been fashionable to overuse inheritance long ago, it should be used when appropriate. these diagrams are a good way of introducing the most important parts of a design; each diagram is like a miniature table of contents.

Sphinx integration

selecting an HTML theme and overriding defaults is a chore, but reusing the result is easy. the result (i.e. theme selection and configuration values) is easily updated/reviewed, and propagating documentation upgrades is safe.

the starting point should be a project created by sphinx-quickstart. differences between the generated Makefile and conf.py with the corresponding files in the project should be minimal. as my example illustrates, the difference between a project Makefile and a generated one can be purely additive.

Makefile extensions

any project that includes tests should produce code coverage reports, because they assure product/project managers that the application is maintained conscientiously. it's easy to inject these reports into the HTML build directory.

if your application is a REST API server and you've lost your swagger, add a link to its OpenAPI specification. modifying the Sphinx Makefile to do this requires almost no effort.

Comments

Popular posts from this blog

Improper english

Before retirement ended my last spell of unemployment, i wondered if the timing of that dismissal was ideal. one month earlier or later might have been better? improving a server log was my last assignment. like many other companies, their senior management believed in their culture, technology, and tools. like other well-funded companies, they used Splunk and wanted to use JSON format. nobody reviewed the pull request that would have established a baseline for my work. their Splunk dashboard code was not versioned. Overcommunicating JSON can be ideal, and creating a data structure to discover if a log entry describes an error is easy and reasonably fast, but computers find strings very quickly. a faster algorithm uses less electricity; computer activity is human activity. ...

Obsolete versions

Once upon a time, upgrading packages was just downloading and installing files. after a while, it also entailed compiling source code because my operating systems no longer received first-class support. Descent Into Madness after a while, upgrading a package also entailed upgrading the tools needed to make it and their dependencies. i felt like i had installed every (meta-)build system. on one of my MacBooks, Homebrew maintained two versions of Python and two versions of llvm . as projects migrated from Autotools to CMake, library versions became inconsistent. these inconsistencies puzzled me, because the first test one should perform after adding support for another build system is determining if the result is the same. any differences should be eliminated/explained. in real life, most people didn't ...

Cat's whiskers

Online forums are good sources of information and/or habitats for groupthink. Jean Valjean ignored the smell; so can you :-) forums are biased in various ways. for example, woodworkers' opinions about linseed oil are informed by wood finish products. in another forum, we might find a recommendation for finishing wood with linseed oil sold by an art supply store. sauce for the painter is sauce for the woodworker? Slippery when wet when i became interested in safety razors, forums were invaluable sources of information. they are still helpful, but i learned enough to continue on my own. at one point i bought cheap shaving soap thinking that it couldn't be as bad as forum contributors claimed. they were right, but the soap was/is still useful: it stays at th...