Skip to main content
In this lesson, we explore how to use Tabnine to generate inline code comments for our application. Our project features a Python backend built with Flask for image compression using OpenCV and a React frontend for the image optimizer. Although our application functions well, it requires proper documentation. We will review approaches and challenges involved in generating inline documentation for large functions.

Documenting the Python Backend

Our Python backend contains an 80-line upload function that processes image uploads. Below is an excerpt of the code:
Large functions can sometimes confuse auto-generated documentation tools like Tabnine or GitHub Copilot. When generating inline comments or refactoring, these tools might incorrectly suggest the removal of crucial components, such as import statements or logging configurations, which could break the application.
For large functions, consider manually inserting docstrings rather than completely relying on auto-generated comments.
A practical approach is to document the function using a clear docstring at its beginning. Below is an example of how you could document the upload function:
When auto-generating documentation, tools might try to refactor or remove parts of the code, especially for lengthy functions. Breaking down larger functions into smaller, modular functions enhances both code readability and documentation quality. If refactoring isn’t an option, manually reviewing and editing the generated documentation is essential to maintain functionality.
Always verify that auto-generated documentation does not remove essential code segments like import statements or logging configurations.

Documenting the React Frontend

The React frontend of our application also contains functions that manage intricate logic. For instance, the main App component handles state management for image selection, file size formatting, and interaction with the image optimizer API. Below is an excerpt from the React code:
In auto-generated documentation workflows, tools may attempt to remove or alter necessary components such as import statements or the export default declaration. To prevent such issues, you can manually insert doc comments at key locations. This is an example for the App component:
By inserting these remarks manually, you ensure that essential code remains intact and the documentation is accurate, clear, and maintainable.

Conclusion

This lesson demonstrates the challenges of using AI documentation tools like Tabnine with large functions and multi-file applications. The key takeaways include:
  • Auto-generated comments for large functions may inadvertently lead to code changes.
  • Manual insertion of documentation is beneficial, especially for critical functions.
  • Refactoring large functions into smaller, modular components is a best practice that simplifies both the codebase and the documentation workflow.
  • Always verify that auto-generated documentation does not remove vital code segments such as imports, exports, or logging setups.
By understanding these nuances, you can effectively document both your Python backend and React frontend, ensuring that your code remains clear and maintainable as your project grows. Happy documenting!

Watch Video