I am a python programmer and I write a lot of doctests , which is a python module that allows you to write tests as examples of a function using each function in the documentation line. Take a look at an example from here :
def factorial(n): """Return the factorial of n, an exact integer >= 0. If the result is small enough to fit in an int, return an int. Else return a long. >>> [factorial(n) for n in range(6)] [1, 1, 2, 6, 24, 120] """
The last two lines are an example of the use of the function and can be performed using the doctest module. Thus, you achieve this:
- You put an example of using the function, so your users will know how to use it;
- if you include a test in your test suite and often run tests, you will notice that if this example is violated by a code change
- writing such examples does not take too much time.
I usually start by creating stub functions and writing doctrines to get an idea of how each function will work and what are the expected inputs / outputs; thanks to this approach, I always have at least a brief documentation of each function and module that I write.
From time to time I write a longer document explaining how my modules can be used (for my colleagues), and I always use the doctest syntax; however, when I solve your question, I never do more than this, sometimes I can write a blog comment about my work or in the library that I wrote, but I don’t have time to write longer documentation.
dalloliogm
source share