💾 Archived View for dioskouroi.xyz › thread › 24939227 captured on 2020-10-31 at 00:51:03. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Ask HN: Why are documentation only showing 1 example if any

Author: julienreszka

Score: 9

Comments: 10

Date: 2020-10-30 04:39:42

________________________________________________________________________________

disposedtrolley wrote at 2020-10-30 08:33:25:

Quality documentation is very difficult to produce and maintain.

On top of adopting a different mindset when writing docs (you'll need to phrase concepts and provide examples to cater for users who probably don't share the same intimate knowledge you have of the codebase), there's a high cost associated with upkeep. Ensuring that your docs always align with the implementation might be straightforward for smaller applications, but as your API surface grows so will the cracks that outdated documentation will slip through.

There are a few examples of tools which are designed to lessen the burden (that I know of):

- To generate usage examples from your code, Go has the idea of testable examples (

https://blog.golang.org/examples

) which get rendered in the documentation but are declared as normal functions. These can be easily unit tested.

- To provide usage examples in code without resorting to unit tests, Clojure has `comment` forms (

https://clojuredocs.org/clojure.core/comment

) which are normal expressions but ignored by the compiler. You can define arbitrary expressions within a comment form (e.g. to execute another function), so these can be used to define usage examples and placed next to the functions they call.

1_player wrote at 2020-10-30 08:23:55:

On the opposite, and more irritating side, you have documentation like Ansible's where the core functionality is only explained by examples.

I would've loved to know the exact format of the inventory file specified on a single page, or the list of all supported Jinja methods with a quick description of each, but no, pages and pages of just conversational examples.

Which is great when starting out, and absolutely awful past that, so you is click through maybe relevant pages and Ctrl-F what you're looking for.

zufallsheld wrote at 2020-10-30 18:26:53:

To add, I like ansibles module documentation. Every option is explained and most times there is more than one example in how to use the modules.

gostsamo wrote at 2020-10-30 04:41:45:

Because writing documentation is boring and done by volunteers. Unpaid people tend to do stuff that is interesting for them, not useful for you. Even paid people tend to do the same if not pressed, so what you get is what you pay for.

viraptor wrote at 2020-10-30 06:23:43:

Depends on the documentation. Here's 20-ish examples for one function:

https://relishapp.com/rspec/rspec-mocks/docs/setting-constra...

If you have people and time for docs, you'll have good docs.

bjourne wrote at 2020-10-30 14:09:52:

Because programming documentation is often written by programmers and not teachers and most programmers doesn't know how to teach. Documentation without any (or few) examples is like math textbooks with only proofs and no exercises.

fiftyacorn wrote at 2020-10-30 16:21:50:

If it's open source the unit tests are often the best place to start for examples

de_watcher wrote at 2020-10-30 07:40:10:

We just have automatic tests that use the thing in every possible way. We have them because that's how we've developed and debugged the function. Best documentation ever.

tcbasche wrote at 2020-10-30 09:43:56:

A comprehensive unit test suite is the best documentation your code can have :)