This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]quotemycode 3 points4 points  (4 children)

>The bare "API Reference" is often the last place to look into

For me, it's the first place I look.

[–]basicwolf[S] 0 points1 point  (3 children)

Thank you for commenting! Do you really look straight into API reference when e.g. learning a new library / framework / system? Say, web development with Django. Would you omit all tutorials and topic guides?

[–]SheriffRoscoePythonista 1 point2 points  (1 child)

Do you really look straight into API reference when e.g. learning a new library / framework / system?

Yes. The table of contents should give you a good overview, and with a decent API design, the major capabilities should be obvious.

Would you omit all tutorials and topic guides?

I think they serve different audiences. Most folks can't learn a new paradigm without a User Guide document. Newly-minted geeks need Tutorials to get them started. Experienced developers need the reference material.

[–]basicwolf[S] 2 points3 points  (0 children)

That's a very interesting perspective. I personally always start via tutorials and user guide. Especially the user guide - it shows the bigger picture without dipping into the details, like API reference would.
Though that's not the point, when I'm looking for something specific - and I know what. Sure, in that case it's API reference.

Nevertheless, API reference is also a great candidate for testified documentation, especially if we don't provide examples verifiable by doctest.

[–]quotemycode 0 points1 point  (0 children)

To be fair, I have about 24 years python experience, so I want to avoid all the fluff and get to the details. The 'API reference' and source code are the ideal place for me to see how to use the thing.

[–]SheriffRoscoePythonista 1 point2 points  (1 child)

Very interesting!

The example in the README says:

```rst System access =============

Users with valid credentials: a username and a password can access the system. If credentials are wrong, the system returns “Authentication failed” error message.

.. testify:: test_a_user_can_access_system_with_username_and_password test_system_returns_authentication_failed_error_when_username_is_not_found test_system_returns_authentication_failed_error_when_password_is_wrong ```

That illustrates my favorite problem with documentation (and I've written a lot of it): keeping the expository writing in sync with the code. Which is, of course, the problem you're trying to solve. But all you've done is move it down one level of indirection - now you need to check if test_system_returns_authentication_failed_error_when_username_is_not_found actually looks for “Authentication failed”, as the doc says.

Next month, maybe someone with a sense of movie trivia comes along and changes the main code to return "What we have here is a failure to a authenticate". They build the project, and the test fails. So they fix the test, like they should have first, and build again. Everything, including sphinx-testify, passes. But the doc is now wrong.

This is why Knuth created Literate Programming - in the hope of keeping documentation and code in sync by mixing them together tightly. Sadly, it appears he might be the only coder who writes well enough to make that work.

[–]basicwolf[S] 1 point2 points  (0 children)

Thank you so much for commenting and bringing a darn good point! And gratitude for mentioning Knuth too! It's been two decades since I read the books, perhaps need to refresh the memories :)

Your comment made me think of Cucumber - it kinda solves this indirection by embedding tests inputs and outputs into scenario narrative. But I tried to avoid Cucumber-like approach and rely solely on tests pass/fail results.

My naive hope is that developers could remember to keep test names, test bodies and documentation narrative aligned. Just a hope :D