|
|
|
How should i document my code?
|
|
16 points
by jonloldrup
3433 days ago
|
|
I have been working on a hobby project in JavaScript/three.js + browserify for 5 years now. I've been pretty good at testing my code and refactoring it whenever appropriate. I thus have more than 2500 test cases and I feel that my code is pretty solid. However, I haven't been so good at documenting my code. I have some comments here and there in the code base, pertaining to certain functions. But that's it. I miss documentation that explains all the 'glue' and the big thoughts in the code. I always wish I had this, whenever I revisit code that I wrote a while ago. So what's the best approach to this? Is there any kind of systematic approach to this task, beyond autogenerating API docs using / ... */ comments? Or any kind of guideline I should have in mind when starting this project? What's the best practice when embarking on documentation projects like this? |
|
For folks using your API, there are two types of documentation you want:
1) Tutorial: Documentation that guides the user through a few steps of working with the API. This should be an integrated experience. The aim is to help a user build a mental model of your project and introduce them to the shape of the major parts of your API.
Example: https://developer.gocardless.com/getting-started/api/introdu...
Since you're doing this for a library that you can write automated tests for, you should consider showing your user how to test. This helps prevent a user from getting lost and gives them a clearer way to integrate with the rest of their tooling.
2) Reference: Documentation that someone can use to look up the answer to a specific question that they have. This is not an integrated experience but should integrate well with their workflow when building something and searching for answers. The goal here is to be highly searchable, which requires thinking about what words they would look for when trying to find it.
Example: https://developer.gocardless.com/api-reference/
This is something I love thinking/talking about, so feel free to email me if you want to videochat and bounce ideas off me. My email is in my profile.