JEP 467: Markdown Documentation Comments
openjdk.org
openjdk.org
HTML may produce nice output when everything is processed, but inline it’s ugly and distracting. This is exactly the problem Gruber designed markdown to fix.
Personally I’m not big on /// as it’s pretty visually heavy. I understand their reasoning for not allowing it in /** */ blocks. I’d be happy with maybe //** */ or /*** */, but I’m just bike-shedding.
Its a great QOL feature idea and I’ll be happy when I can start using it.
I'm very used to consider line and block comments semantically different. To my mind block is javadoc (or for text addressed at the reader that is not meant for tools, in short for prose) whereas // is for killing source lines (and for killing block comments for tools). With the corollary that // would be absent from perfectly clean code, that removal of // is never wrong. In my own projects, I even add an exception mechanism for // that should be kept, they can be marked with ///*why*/, and why should better be good. "why" can be a key further explained in a regular block comment, the idea is that those lines can be cleanly enabled/disabled/removed with regex.
On a very abstract level, I could describe my position as "languages should have multiple forms of comments that have clearly defined semantic differences". I consider this a paradigm change similar to how modern languages have started to declare one style guide the blessed one, even if technically whitespace is just as insignificant as in the old days of "do what you think is best".
What I do miss, from the old doxygen days, is support for trailing comments for when you want to add a few short words to a field without begging for attention too much. Something like
int count = 0; /** quuxes encountered */
And for inline javadoc in multiline argument lists, which I believe to become ever more common in the postOOP age. These could be implicit @param in the slurp javadoc, just like the markdown lists in the future work part of the JEP (where I to see a real benefit of magic headline/list pairs over repeated @param or @throws): void slurp(
/** quuxes ready to be slurped */
int todo,
/** quuxes slurped before */
int done
) {
(Of course I'm mostly looking at KDoc here, where they already have markdown but where multiline parameter lists are even more common than in current/future java)I was trying to find the issue in a web search, but failed.
If I remember correctly it was important to keep multi-line doc comments in the language even if they are seldomly used, because it allows developers using assistive technology the possibility to read doc comments uninterrupted.
I imagine that it isn’t hard for developers with screen readers to have an editor macro turn /// comments into /** and back in the rust world. But if /// were the only option then there is no such workaround for developers and their only options are to endure or request the improvements (or send a PR if using open source tools).
/**
*
*/
that I find this visually off-putting. Almost as much the string interpolation in string templates. /***
would be much better.Also /// will be read as a comment with a line starting with a slash until the tooling is updated.
Thanks.
```java id=example
class HelloWorld {
public static void main(String... args) {
System.out.println("Hello World!"); // @link substring="System.out" target="System#out"
}
}
```
(However, some JS highlighting libraries will strip pre-existing HTML in the code (e.g. PRISM.js [2], as is mentioned in the JEP), negating the @link tag above. Highlight.js [3] seems fine though.)[1] https://openjdk.org/jeps/413 [2] https://prismjs.com/faq.html#if-pre-existing-html-is-strippe... [3] https://jsfiddle.net/LFJKR/
> The text must be written in HTML with HTML entities and HTML tags. You can use whichever version of HTML your browser supports.
0 - https://docs.oracle.com/javase/8/docs/technotes/tools/window...
But if you're going to link to the docs, at least link to the modern Java Documentation, not some ancient Java 8 version of the javadoc tool:
https://www.oracle.com/technical-resources/articles/java/jav...
https://stackoverflow.com/questions/16481230/allowed-html-ta...
This is similar to HTML in Markdown, incidentally.
Did manage to make it work with AsciiDoclet?
The MarkDown code character backtick is especially great for Java since it’s not a metacharacter in the Java syntax.
[1] I didn’t mean writing docs in Java itself, whatever that would look like.
So I don't use any advanced html tags and stuff. Of course I use @link, which is the most useful feature of javadoc.
BTW, maybe the 'meaning' of <style> tags should be clarified for ambitious documenters... It seems they only affect the one javadoc they are inside of, which is pretty useless.
In GFM, individual line break are translated to line breaks in the output.
Also wish C# would switch to Markdown comments instead of this XML nonsense. This JEP looks so clean.
What's dead in many environments is going fancy with the HTML. I think most codebases have nothing or very little in terms of formatting outside the @something keywords. Then the only trace of html is the pain of typing < instead of <. For things like emphasis, chances are people already write it in markdown snytax instead of html even assuming that the markdown will never be read in a formatted way.
Automated API documentation based on code comments never really died, but the popularity of dynamically typed programming languages had a lot of devs writing API docs separately by hand for a while. Even though some dynamically typed languages had tools for it, they were ignored because nobody had reliable IDE integrations for Javascript/Python, and maybe (?) because of a sentiment that it is a weird enterprise thing to do. Many open source projects adopted casually-written documentation more focused on usage examples, skipping out on detailed documentation of procedures that are deemed too obvious to need docs.
But nowadays we are in a golden age of doc generator tools across various languages.
From having done rust development, you get used to it pretty quickly and it becomes no noisier than the repeated stars in the block comments.
I’d prefer just having the comment block start with `/*#` personally since Java already standardized on block style comments but this is hardly “strictly worse [than all other languages]”
Line comments in general have the advantage that they can be trivially nested, and the nesting be immediately recognizable as such. For any new programming language, I would only support line comments, for that reason.
Here's best quick (am on mobile) example I found:
https://blog.jetbrains.com/idea/2020/03/intellij-idea-2020-1...
As if they weren't recognizable as such before
> The tool support is trivial, and you can always run a simple regex to fix it up.
Why all this when you could avoid it from the start?
> Line comments in general have the advantage that they can be trivially nested, and the nesting be immediately recognizable as such.
Has nothing to do with and is not applicable to comments written in Markdown
Rust likewise has a standard and parser built in (markdown in this case) and even took it a step further and allowed your example doc code to be runnable and testable.
Personally I've long wanted to see JavaDoc allow markdown. As the JEP examples show, trying to make any javadoc comments that format nicely for the javadoc parsers means making documentation that's hard to read when you're in the code itself. Even the most basic of markdown parsing covers probably 90% of what you'd put in javadoc, and would make reading (and writing) good JavaDoc that much better.
It won't. The `javadoc` tool parses doc comments and outputs HTML, not `javac`.
> This seems like the use case of an IDE extension, or a website that host code
Disagree. I find often enough that I read Java code in vim or simply using less or cat. Having doc comments that are more readable would be helpful. And it seems silly that every website code hosting solution should have to implement a javadoc parser, when a much simpler solution exists: use markup that is readable as-is.
If you don't want to use this, that's fine; you can continue writing your javadoc comments as you have in the past. That's no reason to suggest that the rest of us should be stuck in the past.
I don't think javac does anything with javadoc or will do anything on this new Markdown doc. It's just comments it will ignore. So nothing should be added to the compiler - it's a separate tool that handles source to javadoc generation.
>This seems like the use case of an IDE extension, or a website that host code, not the compiler itself.
That's how we get complicated setups with external dependencies, 20 non-standard ways to do something, different habbits from project to project and company to company, and a mix of different (new and legacy) versions of those non-standards in any larger codebase.
There's also the issue of keeping things up to date: it's much more likely that a programmer is going to keep docs up to date if the doc is right there along with the code than if it's in a separate file.
Not to mention... XML... ugh, no, let's not.
And I'm not suggesting that there would be no documentation in the code. Javadoc is written for consumers of the code being document. That is incorrect. The comments should be optimized for the developers of the code itself. And it should not explain what the code does if you can just read the code itself.
So again, IMO, javadoc is a mistake. It mixes up two largely different things.
Also, when you downvote someone, it's not supposed to be because you don't agree with their view. You downvote someone when they say something that does not contribute to the discussion. But do what you will ...
Is there a reason why in addition to being inline it couldn’t also be on its own and off to the side?