r/ProgrammerHumor • • 1d ago

Meme readTheDocumentation

Post image
8.5k Upvotes

129 comments sorted by

View all comments

Show parent comment

47

u/Hollowed-Be-Thy-Name 23h ago

I can't remember a single time I've read documentation and didn't find out it was wrong or outdated.

Probably just confirmation bias, but it happens often enough.

26

u/danielrheath 21h ago

My approach is source-diving; the docs might be missing or lies, but it’s harder to obfuscate what the actual code does.

6

u/ITaggie 21h ago

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.

9

u/Historical_Course587 14h ago

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.

3

u/NotYourReddit18 11h ago

And AIs aren't guaranteed to write accurate documentation either, LLMs just making stuff up is one their biggest problems.

1

u/frogjg2003 2h ago

But it's a much easier task to have the AI just verify that the documentation is correct. It still has the possibility of error, but with both the documentation and the code, the chances are pretty low.

7

u/Muhznit 21h ago

You should look into executable documentation. Python introduced it and it's lovely. Rust and Go adopted it as well.

2

u/DezXerneas 14h ago

Wait, I don't get how it works, could you explain a bit?

2

u/Muhznit 10h ago

Actually that's my bad, python's documentation has a much better set of examples.

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                                                                                                                                                                                                                
import doctest                                                                                                                                                                                                                        
                                                                                                                                                                                                                                      
def is_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"}                                                                                                                                                                     
    return thing in good_things                                                                                                                                                                                                       
                                                                                                                                                                                                                                      
def main():                                                                                                                                                                                                                           
    doctest.testmod()                                                                                                                                                                                                                 
                                                                                                                                                                                                                                      
if __name__ == "__main__":                                                                                                                                                                                                            
    main()

2

u/DezXerneas 6h ago

Oh, so functionally you're just writing your tests directly in your code without a tests.py for the basic stuff. That's really cool, I think I might start integrating it into my codebases too.