I spent the last couple of weeks learning how to document Python code as well as Angular and React projects. I figured this is best done when the project is in a nascent stage, so as to establish this as the baseline going forward.
The best documentation experience was with Angular. I used Jsdoc to document the Typescript code, but for Angular, there is a package compodoc that produces an elegant web document. This is the typical documentation for a Angular component:
/**
* Generates a container for the video player
*
* @param {number} width The width of the container (optional)
* @param {number} height The height of the container (optional)
* @returns A container for the video and controls
*
* @example
* Without any inputs, container adjusts to browser window
*
*
* @example
* With only width, container has fixed width and
* aspect ratio of 16:9
*
*
* @example
* With only height, container has fixed width and
* aspect ratio of 16:9
*
*
*/
After documenting all components and utility functions, I created a very basic config file for the documentation and saved it in tsconfig.doc.json:
{
"include": ["src/**/*.ts"],
"exclude": ["src/test.ts", "src/**/*.spec.ts", "src/app/file-to-exclude.ts"]
}
Running compodoc produces an entire directory of html files that depicts the entire app graphically.
Very impressed to see documentation arranged in such a visually appealing manner.
In comparison, documentation for the React app was with Jsdoc and another package better-docs which has a special addition for components. Though running jsdoc produces another directory with html files, the links are broken and navigation seems a bit jumpy.
For Python, I used almost a markdown approach. Classes are documented as this example:
'''
Base view for a course based on course URL
Attributes
-------------
serializer_class : class
CourseSerializer class
user_model : class
User class
lookup_field : str
The field in URL used to look up model instance
Methods
-------------
get_queryset() : Base method for course list view
get_object() : Returns course model instance
'''
The VSCode IDE displays the documentation once you hover over a class. A function has documentation similar to JS:
'''
Create a new course - POST request
Parameters
--------------
request - dict
Raises
--------------
400 error
Course title missing or not unique
Course price missing for non-free course
403 error
If course created by non-admin user
Returns
--------------
201 response with course data
'''
Next step is to find a package that will convert these doc strings into html viewable pages that can be committed into Git.

No comments:
Post a Comment