views:

47

answers:

2

Robert C. Martin's book Clean Code contains the following:

HTML in source code comments is an abomination [...] If comments are going to be extracted by some tool (like Javadoc) to appear in a Web page, then it should be responsibility of that tool, and not the programmer, to adorn the comments with appropriate HTML.

I kind of agree - source code surely would look cleaner without the HTML tags - but how do you make decent-looking Javadoc pages then? There's no way to even separate paragraphs without using a HTML tag. Javadoc manual says it clearly:

A doc comment is written in HTML.

Are there some preprocessor tools that could help here? Markdown syntax might be appropriate.

+3  A: 

I agree. (This is also the reason why I am -strongly- opposed to C#-style "XML comment blocks"; the Javadoc DSL at least provides some escape for top-level entities!). To this end I simply do not try to make the javadoc look pretty...

...anyway, you may be interested in Doxygen. Here is a very quick post Doxygen versus Javadoc. It also brings up the issues that you do :-)

pst
Ah, I didn't know that Doxygen works with Java :-) The syntax seems to be quite compatible with Javadoc, except for the HTML tag nonsense, so it might be possible to write docs so that they look good when generated with Doxygen, but still remain readable when generated with the standard Javadoc tool.
Joonas Pulakka
A: 

HTML is nothing I'd like to see in "normal" comments. But for Tools like JavaDoc, HTML adds the possibility to add formatting information, bullet points etc...

I would distinguish these two things:

  • non-javadoc code comments are for the programmer who maintains or enhances the code i question. he has to dig through existing sources, and any HTML in coments just doesn't make things easier. So, ban it in normal comments.
  • javadoc-comments are used to generate documentation. Use HTML where it helps. But a very limited subset of HTML should suffice.
Axel
The fact that a very limited subset of HTML usually suffices is exactly the reason for replacing that subset with Markdown -kind of syntax (just as you wrote bullet points above without using HTML).
Joonas Pulakka