Product SiteDocumentation Site

Chapter 8. Explaining the Code

Karsten Wade

Red Hat Community Architecture
8.1. Introduction
8.1.1. Exercise - Practice Good Code Commenting
8.2. Common tools and Processes for Open Source Documentation
8.2.1. Exercise - Document Your Team
8.3. Five Steps for Technical Writing
8.4. Exercise - Plan Your Technical Document
8.5. Using Documentation as a Way to Get Involved
8.5.1. Exercise - Getting Involved
8.6. Collaborating on Open Documentation
8.6.1. Exercise - Collaborating on a Small Document
8.7. Documenting Technical and Community Proceedings
8.7.1. Exercise - Document Proceedings
8.8. References and Further Reading

8.1. Introduction

People are going to tell you documentation doesn't matter. In a perfect world, it doesn't! If all code were self-evident and all programs worked for users without needing help, if all work and communities were easy to participate in, perhaps we could do without documentation. Of course, that would require all people to think and act in similar ways; we may never be without documentation simply because we are a diverse species.
In FOSS, documentation is a key tool of transparency and participation. You have to document everything that you do in a FOSS project, not just the code. Next year when you need to remember why a technical decision was made, the answer is coming from a combination of mailing list archives, wiki page history, and well written version control log messages. A question of why you have specific commit rules or code styles? Mailing list archive and wiki page history are your friends.
There are two main ends in the spectrum of documentation:
  1. Content written ad hoc and in the flow of working; it captures the moment; examples are comments in source code, commit log messages, and notes taken during a meeting.
  2. Content planned as a document of some size; it captures a version in time; it follows a more rigorous process with a higher quality result.
Part of your journey is learning when to practice each end of the spectrum. Properly done, the ad hoc just-in-time components add up to coherent whole that approaches a full document, but it usually requires a restructuring and culling of content to make it gain the higher quality.
From a practical standpoint, here's a piece of code. What does it do? Take 2 minutes and see how far you can get just by looking at the code snippet alone.
def findAllPrevious(self, name=None, attrs={}, text=None, limit=None,
                   **kwargs):
   return self._findAll(name, attrs, text, limit, self.previousGenerator,
                      **kwargs)
Even if you had written this code yourself six months ago, how likely would you be to remember what it does now?
How about this?
def findAllPrevious(self, name=None, attrs={}, text=None, limit=None,
                    **kwargs):
    """Returns all items that match the given criteria and appear
    before this Tag in the document."""
    return self._findAll(name, attrs, text, limit, self.previousGenerator,
                       **kwargs)
Now go to this link.
Which of those methods gives you the quickest idea of how to use that particular piece of code? If you had to figure out how to use this XML parsing library and make something in the next ten minutes, which level of documentation do you hope the code would have?
Apply the same thinking to the processes and proceedings of a FOSS community. If you had to find out in the next ten minutes who had done a particular commit to the code in version control and why they did it, you would want the project to use tools and processes taught in this book. Any time you want to understand why a page in Wikipedia is edited a certain way, the history and discussion buttons reveal a rich level of information and interaction that are the backbone of what makes it a useful and reliable source:
According to Wikipedia, documentation "is written text that accompanies computer software. It either explains how it operates or how to use it." For software engineering purposes, operate/use includes manipulating the source code as well as using the application. Documentation is a sanity-preserving tool for users of and potential contributors to your project, including your future self ... and perhaps your future boss or coworker.
In FOSS projects, documentation is a way of life. It is more than developer documentation in code and README files. Practicing the kind of radical transparency that makes FOSS successful means all of these things and more:
  • If your code is poorly commented and opaque, people know and tell you;
  • When ideas that become decisions are documented throughout the entire discussion, everyone can see and understand the logic; these ideas are:
  • You can share the burden of documentation with fellow developers, making lighter work for all;
  • The extra effort of documenting meetings and proceedings pays off many, many times over when:
There is also content written to document an event, such as notes for a class or technical conference, or minutes from the proceedings of a meeting. In open source projects, similar tools and processes are used in this type of documenting. Keeping transparent proceedings of meetings and similar events is a useful skill for FOSS developers.
At the end of this chapter you should be able to:
  1. Document your project in a way that encourages other people to discover, use, and contribute to it.
    • Follow a good methodology for technical writing.
    • Write good commit log messages.
    • Document your code and other FOSS work as you do it.
  2. Engage in an open collaboration on documentation, whether in source code or on a wiki.
  3. Participate as part of a community in documenting a proceeding or event.
  4. Explain the value of documentation to open source engineering.
Kat Walsh: "Not just encourage other people to discover and use it themselves, but make them want to share it with other people and go 'hey, look how good this is.'"
Every technical effort has a requirement for documentation. The project's ability to make writing, editing, and publishing as easy as possible is the main key to attracting and retaining contributors.
According to Mozilla, developer contributions to documentation greatly increased along with a new community of writers, editors, and translators. This all resulted from reducing the barriers to success that made even experienced developers too frustrated to document properly.

8.1.1. Exercise - Practice Good Code Commenting

Throughout all the exercises in this book practice doing good commenting and documentation for your coding efforts.
  1. Write thorough comments in all your source code.
  2. Trade sources with another student and attempt to make sense of the source from the documentation alone.
  3. Write at least one wiki page of developer documentation for each program you write or work on:
    • Share this burden with other students working on the same code base
    • Contribute this to any FOSS projects you work on for this class