Yup, a lot of my work involves open source projects so I have the benefit of being able to go through the authoritative source code myself if need be. Really sucks for stuff like "black box" appliances though.
This is one of those situations where even though I believe a motivated human could do a better job, in practice AI will produce better results because humans just aren't motivated to write good documentation.
Basically the idea is that in whatever docstring that you usually add to a function for documentation, you include some special syntax to illustrate an example of how to use that function, you have some tool to extract and run that example. Thus, you become able to catch outdated documentation as a part of your build process.
It's easily one of my favorite things about Python. I can set up some quick-and-dirty tiny functional unit test and keep it in version control with the rest of the code. Personally I like writing my doctests similar to this:
#!/usr/bin/env python3
importdoctestdefis_this_good(thing:str)->bool:"""
Checks if the thing is a good thing.
Doctests are good.
>>> assert is_this_good("doctests")
Facism is not.
>>> assert is_this_good("facism") == False
Being able to drop into the python debugger when an assertion fails from a
doctest is cool, but not something to include in CI/CD
>>> some_bullshit_condition = False
>>> assert some_bullshit_condition, breakpoint()
"""good_things={"doctests","puppies","boobs","world peace"}returnthingingood_thingsdefmain():doctest.testmod()if__name__=="__main__":main()
In may situations, the documentation only covers 7% of the actual behaviour and almost none of the corner cases and the user's only choice is to empirically discover stuff.
Also, I've probably saved more time by doing this. If I read the docs for every single thing I've every used I'd have spent so much time. It's better to just throw shit at the wall for like 5-10 min and then rtfm if you still don't get it.
View all comments
136
u/xgabipandax 17h ago
Because often documentations are written in a way that is easy to understand if you already know how things work.