Web DevelopmentHow to Write a Good Documentation for Your Open-Source Library (2022 Updated)
Just a few years ago, developers often underestimated the importance of good documentation and did not strive to master the art of writing it. If you look at the products of the Stone Age (i.e., products from a decade ago), you will find among them many libraries that do not have good (or at least some) documentation. Except, perhaps, the most popular. The developers of these libraries believed that a few code examples would be enough for any beginner to understand the idea and be able to use their development skills in practice.
But, due to the rise of the open-source movement, when writing documentation, we have to focus more and more on the end-user. Corporations have realized that the presence in the open-source world helps to attract customers and new developers, i.e., it is a valuable asset. Open source projects create a reputation as a reliable and solid company. As a result, there was a request to write good, solid documentation.
What does good documentation consist of
The project documentation consists of many things. For example:
Collection of recipes
Each of these points serves its own purposes, but the boundaries between them are sometimes blurred.
The README file is often the first opportunity for potential users to get acquainted with your product. It may contain information specific to different types of documentation (reference books, manuals, etc.), but the README file cannot be confused with anything else. This file helps you "sell" your open-source library. At the same time, do not forget that the README text should be concise and informative.
Start with what your library is designed for in general, what user problems it solves. Examples of common use cases can be given. A well-written first paragraph is a great start for any README file.
If your file is longer than one or one and a half pages, it would be a good idea to add content (a list of content).
List the dependent packages that the user will need to install, specify what knowledge he must have in order to use your product. Describe the installation steps. Show basic code examples, preferably real-use case code. Attach a link to more detailed documentation.
Finally, include in your README file information about the product license and a list of contributors. You can also add a paragraph on how to participate in the development of your library. This file is commonly named CONTRIBUTION. Remember that one of the pillars of open-source is respect for other people's time. If your potential contributors can quickly understand the work of your library, everyone will benefit from this.
Reference materials are perhaps the most technical part of your documentation. Its purpose is to list the entire list of functions of your library, their expected inputs, outputs, and side effects, as well as the purpose and implementation examples. The examples in the reference book should be as isolated and self-sufficient as possible.
Background information is often generated automatically. There are also many tools to simplify updating the directory and to make it easier to work with it. But we should not forget that reference materials completely generated by a computer can be difficult for users to perceive. You need to try to include at least one sentence "from yourself" in each point of reference information.
It will be easier for some developers to understand your library if they have the opportunity to understand how individual functions are implemented. Therefore, a direct link to the implementation of the function in the code of your library will be a good addition to the reference information (although not mandatory).
The guide (guide, tutorial) should guide the user through all the functions of your library. If we are talking about large, popular general-purpose frameworks, the manual may be the most voluminous part of the documentation.
Start the guide by describing the scope of the library and what prior knowledge the user should have. For example, if we are talking about a library that helps manage HTTP requests, it is logical to expect that the user should be at least a little familiar with the basic concepts related to this topic.
In the description of any topics, first cover the most basic ones, gradually moving to the more complex ones. A good starting point would be to describe the installation process for different systems.
When you write a manual, try to imagine that a group of people is sitting in front of you and you need to explain to them how your product works. Remember that in terms of explanations, it's better to overdo it than to leave some concepts undeciphered — this way you will show more respect for users.
If possible, supplement the text with images and diagrams, as well as code examples. The code in the documentation should be as complete as possible so that the user can simply copy parts of it. At the same time, it should be divided logically and supplemented with comments on the application of the functionality presented in the code.
Don't forget to test the code in the examples as well. If the user copies a piece of code, it should be working. I can't even convey how angry the user is when the code from the documentation doesn't work.
Collection of recipes
If we are talking about large general-purpose libraries, the recipe collection is a collection of ready-made, carefully verified solutions to common problems that users may encounter when using your library. Unlike the manual, where new concepts are explained on the basis of those explained earlier, in the recipe book, each solution should be self-sufficient. The application of the functions necessary to solve the problem can (and should) be explained in more detail in the recipe book than in the manual.
The recipe collection is not a mandatory part of the documentation for small and specialized libraries. It makes sense to add it only if the explanation of the concepts is more complex than is acceptable for the text of the manual. In this case, the collection of recipes can be considered as a collection of short tutorials on achieving the desired result.
Speaking about the differences between the user manual and the recipe book, one more aspect should be mentioned. The guide mainly focuses on your own library. And the recipe book may well contain links to other documentation, as well as a demonstration of integration with other libraries. In addition, you can even explain why you prefer some language functions over others. This helps the user to better understand not only your library but also the programming language as a whole.
Finally, you can include in the recipe collection examples of when not to use separate solutions. You can also show examples of incorrect code and antipatterns. Most importantly, do not forget to visually separate them from examples of good code and the correct use of solutions.
Strictly speaking, a blog post is not really documentation, but it will still be useful for users. Other parts of the documentation focus on how to use your library in appropriate cases, and a blog post may reveal why it might be needed at all.
A blog post should help you connect with users and tell them how your solution is better than others. You can write about the problem that inspired you to create the library, or specify other reasons for its creation.
Please note that despite the name of the section, it may not be a blog post in the literal sense. You can do all of the above on GitHub Gist and put the link in the README file.
Proofreading of documentation is mandatory. Reading documentation with grammatical and punctuation errors quickly tires. Consider giving your documentation to a native English speaker or someone who knows the language well. If this option is not available, give your contributors the opportunity to make pool requests for documentation and ask them about it separately in the README. There are also a large number of automated tools at your service, for example, Grammarly or Hemingway.
And as I have already said, again, before publishing, you should definitely check all the code examples — they must be working.
Nowadays, when development trends change so quickly, documentation is especially important. By helping users get to know your library and use it, you promote your product in the open-source world.
TOP 10 Identity and Access Management (IAM) and User Management Tools
Explore the top 10 identity and access management solutions that offer robust user management and security for modern digital needs.
Read full article
Unlocking Web Performance: A Deep Dive into Static vs Dynamic Rendering with NextJS
Static vs Dynamic Rendering with NextJS - choose the best implementation for your web app.
Read full article
Explore microfrontends: their benefits, challenges, and managing complexities of micro frontend architecture.
Read full article