DEV Community

Discussion on: Any tips and tricks for code documentation? #discuss

Collapse
 
misterwhat profile image
Jonas Winzen • Edited

Writing proper documentation is an iterative process. We usually use the following pattern at IBM:

Preparation and Writing a first Draft

Comment your code extensively, explain especially public facing functions very detailed. Explain parameter and types.
Then wait some days, extract the comments and use the extracted comments to write documentation. Try to not look too much at the code during this step, in order to avoid getting lost in details.

Proof Reading

  1. Get somebody on board for proofreading and checking, if the documentation is comprehensive and whether other people who don't know about the code, can follow along
  2. Write down any questions that came up by this person. Try to answer the questions within your documentation, try to avoid adding extra subsections, that only answer these questions in specific. Instead try to add information to your documentation, that clarifies the questions
    • To also answer related questions, keep the added information as general as possible!
  3. (optional) Get another person on board
    • Repeat the Proof Reading steps with this person
  4. Repeat the Proof Reading process with these persons

You can repeat the process until you find your documentation in a mature state. Dragging in more people ensures that the documentation not written in a way that is tailored to one specific reader. Each new pair of eyes gives you a new perspective on what is missing, wrong or difficult to understand.

Collapse
 
moe64 profile image
Moe • Edited

I really appreciate this detailed explanation. I definitely don't want to fall into the trap of writing docs that are only understandable by me. So I will follow the steps for the first draft. Then I ask the person who will do our code review if they will be open to give us feedback on our docs also.