views:

224

answers:

6

Hi, I am writing a C++ static library and I have been commenting with doxygen comments in the implementation files. I have never really had to care very much about documentation but I am working on something now that needs to be documented well for the users and also I am trying to replace my previous bad habit of just wanting to code and not document with better software engineering practices.

Anyway, I realized the other day that I need a couple different types of documentation, one type for users of the library(doxygen manual) and then comments for myself or a future maintainer that deal more with implementation details.

One of my solutions is to put the doxygen comments for file, class, and methods at the bottom of the implementation file. There they would be out of the way and I could include normal comments in/around the method definitions to benefit a programmer. I know it's more work but it seems like the best way for me to achieve the two separate types of commenting/documentation. Do you agree or have any solutions/principles that might be helpful. I looked around the site but couldn't really find any threads that dealt with this.

Also, I don't really want to litter the interface file with comments because I feel like it's better to let the interface speak for itself. I would rather the manual be the place a user can look if they need a deeper understanding of the library interface. Am I on the right track here?

Any thoughts or comments are much appreciated.

edit: Thanks everyone for your comments. I have learned alot from hearing them. I think I have a better uderstanding of how to go about separating my user manual from the code comments that will be useful to a maintainer. I like the idea that @jalf has about having a "prose" style manual that helps explain how to use the library. I really think this is better than just a reference manual. That being said...I also feel like the reference manual might really come in handy. I think I will combine his advice with the thoughts of others and try to create a hybrid.(A prose manual(using the doxygen tags like page, section, subsection) that links to the reference manual.) Another suggestion I liked from @jalf was the idea of the code not having a whole manual interleaved into it. I can avoid this by placing all of my doxygen comments at the bottom of the implementation file. That leaves the headers clean and the implementation clean to place comments useful for someone maintaining the implementation. We will see if this works out in reality. These are just my thoughts on what I have learned so far. I am not positive my approach is going to work well or even be practical. Only time will tell.

+4  A: 

I think the best approach is to use Doxygen for header files to describe (to the users) how to use each class/method and to use comments within the .cpp files to describe the implementation details.

Kyle Lutz
Thanks for the comment Kyle. Makes sense, my only concerns would be the size of the header file and sometimes my doxygen comments can be somewhat cryptic to get the right formatting for the manual, which leaves the header file large and hard to read. It still might be the best option, I will have to think about if further. Thanks again.
csmithmaui
If you have a fully commented header file I would just refer your users to the generated documentation rather than having them read the header file itself.
Kyle Lutz
ahh...I see. Ok...thanks!
csmithmaui
I've never ever seen generated "documentation" that actually documented a library. Can you show me an example of doxygen-style generated "documentation" that is actually useful to library users?
jalf
Qt is a very well documented library (for instance: http://doc.trolltech.com/4.6/qwidget.html). They use an internal tool but the same can be created with Doxygen.
Kyle Lutz
It is well documented. But on the link you gave me, I have to scroll past literally *pages* of useless cruft that I don't need to know now, but which would've been obvious to me anyway the moment I *did* need it. What's relevant is the "detailed description" a few miles down, past all the class definitions and function prototypes which each have zero information listed about them. Doxygen and related tools are great for adding all the cruft that I don't want to know when trying to understand a library. it doesn't help you with the description, the part that actually matters.
jalf
I'm with @jalf on this one. I tried to use doxygen for a couple years on different projects. It just generates too much crap. I did a lot of tweaking to get it to just show what users want to see, but it simply wasn't worth it. Not to mention the enormous amount of source code bloat it introduces. Code should comment itself, and anything extra people need to know can be written in a small comment above the function. Documentation is best done by hand, still, I think. Let the code be code, let the documentation be documentation, and don't try to mix the two.
GMan
@jalf and @GMan..as much as I wanted to use doxygen...I guess I have been feeling a bit similar in that I know that if I had to look at the documentation that I am generating as someone unfamiliar to the library, it might be hard to get a good understanding of how to use it. Even though all of the classes and methods are documented well, it's hard to know where to start. I can see a benefit to a "prose form" document for the user. It's just not as convenient for me. :( But I really want to build something that is easy to figure out so I think it's worth it. thank for your comments.
csmithmaui
True, documentation isn't convenient for the person writing it, unfortunately. It sucks, which is why so few people do it... ;)But when it's done, it's extremely helpful to the person using the library.
jalf
+6  A: 

I generally believe that comments for users should not be inline in the code, as doxygen comments or anything like that. It should be a separate document, in prose form. As a user of the library, I don't need to, or want to, know what each parameter for a function means. Hopefully, that's obvious. I need to know what the function does. And I need to know why it does it and when to call it. And I need to know what pre- and postconditions apply. What assumptions does the function make when I call it, and what guarantees does it provide when it returns?

Library users don't need comments, they need documentation. Describe how the library is structured and how it works and how to use it, and do so outside the code, in an actual text document.

Of course, the code may still contain comments directed at maintainers, explaining why the implementation looks the way it does, or how it works if it's not obvious. But the documentation that the library user needs should not be in the code.

jalf
thanks jalf...this also makes alot of sense to me. I was thinking that my doxygen generated documentation might be a little hard to read for a user. It's nice in some ways but I felt it lacking in real explanation of how to use the library, but I thought maybe I just need to be more descriptive. One question: Would you have a use for doxygen at all given your comments above?
csmithmaui
I personally wouldn't. But that's my subjective opinion. I have very different needs when reading code and when reading documentation. In documentation, I want details. I want a high level description, and all the gritty details and semantics. And it's ok that it takes up a lot of space. In the code though? Screen estate is at a premium. Every line is costly, it reduces how much code I can see, and so it prevents me from forming an overview of the code. In the code I want as little noise as possible, and I *want* most of the information to be left out, and the comments to be brief.
jalf
fantastic description of when and how to add comments. But I would disagree that all of this description *has* to be outside the code. Where the comments are stored is not a big concern for me.
James Brooks
@James: Of course, when reading the documentation, all that matters is that it is there. But when reading the *code*, the last thing I need is an entire novel interleaved with it. Hence, the docs should not be inside the code.
jalf
+3  A: 

Well done, Doxygen commenting can be very useful both when reading code and when reading generated HTML. All the difficulty lies in Well done.

My approach is as following:

  • For users of library, I put Doxygen comments in header files for explaining what is the purpose of that function and how to use it by detailing all arguments, return values and possible side effects. I try to format it such that generated documentation is a reference manual.

  • For maintainers, I put basic (not Doxygen) comments in implementation files whenever self-commenting code is not enough.

Moreover, I write a special introductory file (apart from the code) in Doxygen format for explaining to new users of libray how to use the various features of the library, in the form of a user's guide which points to details of reference manual. This intro appears as the front page of the Doxygen generated documentation.

mouviciel
mouviciel, is the "special introductory file" just a text file and were do you put it? Does it automatically link to the reference manual when you type the name of the classes, files, namespaces, etc. or do you have to be more explicit? This approach seems like a hybrid between a "prose manual" like @jalf explained and a plain old "reference manual". I like the idea.
csmithmaui
This can be a separate text file with Doxygen tags (e.g. @page, @section, ...) or a documentation part of the main header file of your library. Doxygen automatically links to reference manual. Indeed it is the first page of the Doxygen documentation.
mouviciel
ok...that makes sense. Thanks alot.
csmithmaui
+2  A: 

Doxygen allows the creation of two versions of the documentation (one for users and one for "internal use") through the \internal command and the INTERNAL_DOCS option. It is also possible to have a finer grained control with conditional sections (see the \if command and the ENABLED_SECTIONS option.)

As others have already noted, it is also useful to provide users (and also maintainers sometimes) something at a higher level than strictly code comments. Doxygen can also be used for that, with the \mainpage, \page, [sub[sub]]section and \par commands

Éric Malenfant
Thanks Eric...I wasn't aware of this!
csmithmaui
Of course I'd argue that this doesn't really solve the problem with doxygen. You don't need Doxygen to write this high-level documentation. Open Notepad if you want to write text. Or you favorite word processor. Or (my preferred) create a TeX document. Just because Doxygen defines fields for the documentation you actually need to write doesn't mean that it becomes in any way clearer or easier to write just by putting it into Doxygen. You still have to write the same text. Now it just has to be inside doxygen tax, and it has to be in the source code. But it doesn't save you any work.
jalf
@jalf: Obviously, you have to write the same text. However, it is often useful to be able to refer to the sources' documentation from that text, and vice-versa.
Éric Malenfant
What do you mean? That text *is* the source's documentation. And while yes, you'll probably want to refer to that text from other parts of the documentation, why do you need Doxygen for that? TeX, MS Word and HTML can all create links or references.
jalf
I'm talking about the case where your documentation has two parts. One is the "text in prose form" that you refer to in your answer (Let's call this the "text part"). The other is the documentation generated by doxygen from the sources and comments (the "sources part"). In the "text part", you may want to link to the documentation for some functions or classes in the "sources part". Similarily, in the "sources part", you may want to refer to specific sections in the "text part".
Éric Malenfant
I think what Eric is saying makes sense, albeit I have not ever done this before. Having a prose form manual that links to the reference documentation seems like a good idea to me.
csmithmaui
A: 

I recommend you to take a look at this paper: http://www.literateprogramming.com/knuthweb.pdf

I normally applied those ideas to my projects (using Doxygen). It also helps in keeping the doc up to date because it is not necessary to leave the IDE, so one can make annotations while coding and, later on, revise the final pdf document to see what needs to be updated or more detailed.

In my experience, Doxygen requires some work so that the pdf look nice, the graphs and pics in place, etc. but once you find your ways and learn the limitations of the tool, it gets the job done quite well.

My suggestion, besides what Kyle Lutz and Eric Malefant have already said, is to put long explanations about related classes in its own file (I use a header file for that) and add references to other parts using Doxygen tags. You only need to include those headers in the Doxygen configuration file (using pattern matching). This avoids cluttering your headers too much.

Martin Ruiz
A: 

There is no quick easy answer, good documentation is hard.

I personally feel a layered model is best.

  • high level docs in prose. Pictures and videos are very appropriate.
  • reference level docs should Doxygen (well done doxygen, not just off hand comments).
  • maintainer docs should not show up in the reference docs, but they could still be doxygen as pointed out by by Éric.

I really like the documentation style used in RakNet. The author uses extensive Doxygen comments and provides a generated reference manual. He also provides some plain html tutorials. Best of all he supplies video walk-throughs of some of the more complicated features.

Another good example is SFML. The quality isn't as good as RakNet but it's still very good. He provides a good overview page in the doxygen generated documentation. There are a few plain html tutorials and a plain html Features/Overview page.

I prefer these styles as Doxygen generated documentation is generally too low level when I'm just starting out, but perfectly concise once I'm in the groove.

caspin