There are a few @todo elements (it's part of PHPDoc) sprinkled through D7 core in doxygen doc headers.
A few days ago, sun added @todo to the http://drupal.org/node/1354 doxygen standards doc as a recommendation.
I would like to open that idea up for discussion. My thought would be NOT to recommend that people put @todo comments inside of documentation headers, because they are ideas for the future and generally the idea we have about doc headers is to describe the current state of the function, class, method, constant, etc. not give an idea of its past or possible future.
So I think that recommendation should be removed from the doxygen standards as a recommended practice for our doc headers. I am not advocating removing them from Drupal code comments, just that they not be in the doc headers.
If the community consensus is that we need @todo in doxygen headers, then the API module needs to do something with them. They are currently not being treated in any way, as you can see here:
http://api.drupal.org/api/function/drupal_get_library/7
Options for API display, if we decide we want to recommend people use @todo would be:
a) Strip them out.
b) Make a To Do header on the page.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | drupal.todo_.14.patch | 32.16 KB | sun |
Comments
Comment #1
Crell commentedAs a counter-point, having a @todo can be a good indication of where someone else could jump in with a patch to help improve the code base.
Even if we do recommend their removal from docblocks, we should still have some central listing of inline todos in the API docs. Many IDEs do that, phpDocumentor does that, and it provides a good central list of "hey, you could write a patch for this!"
Comment #2
jhodgdonThat's something to consider... but really I think the issue queue is the usual place to be proposing and tracking things that need to be done, isn't it?
Comment #3
Crell commentedDepends when you think about it, really. There's certainly value to a horribly ugly code block having a "@todo This only scales up to 50 items. We should probably convert it to something that will scale better, but I don't think we can until we get PHP 5.3" right above it. That way, someone reading through the code can see "Oh god that's horrible and it won't scale... Well, at least they know about it and want to fix it. Hey, I do know of a faster way. Let me go write a patch..."
Or even just "@todo This is a dummy implementation for the moment; we'll clean it up later." is useful during active development so you can check in code you know is not yet done but still reasonably functional. Lots of large modules have code like lying around. Parts of Drupal 6 even had "@todo, remove this in Drupal 7 when we can rely on PHP 5" floating about (mostly in reference to horribly ugly reference passing hacks needed to support PHP 4).
For a lot of things, inline documentation, close to what it's talking about, is the most valuable.
Comment #4
jhodgdonI'm not against having @todo tags in the code.
The questions are:
a) Should there be @todo tags in doxygen headers.
b) If (a), should they be displayed on the doc page for that function/file/method/etc. on api.drupal.org.
c) If (a), should api.drupal.org generate a page containing a list of functions/etc. with @todo in doxygen headers.
d) In either case a || !a, should api.drupal.org generate a page containing a list of code items with @todo anywhere in them.
I personally think the answer to all of these questions is no. A developer can probably search the code to find @todo lines without too much trouble, and they might want to search for "todo" without the @ to catch older code comments that may have been marked TODO: instead. (Do we have a coding standard, as opposed to a doxygen standard, about that?).
Comment #5
suna) yes
b) yes
c) ideally yes
d) ideally yes
I'm personally most interested in c) + d), but didn't get around to work on it.
@todo statements are used everywhere, throughout Drupal core, and throughout most contributed modules.
We have a couple of various "todo:", "TODO:", "@TODO:" styles instead of @todo statements in Drupal core, but those will be eliminated/updated over time. After all, it's their single purpose.
Actually, I'm not quite sure what's actionable in here, so marking as needs more info.
Comment #6
sun.
Comment #7
jhodgdonI don't agree with @todo in doxygen headers at all. Why should we be talking about the possible future in a doc header? If code isn't done, it shouldnt' be committed. If it's done, it shouldn't have a @todo in it. That's what the issue queues are for.
Comment #8
sunWell, it's just facing reality. We don't always write "perfect" code, and there are valid cases in which we can say: Committing this code, including the 30 @todos in that patch, is far more worth than NOT committing it.
Recent real-world examples are:
- Field API (CCK/Fields in core)
- Database API revamp (DBTNG)
- File API revamp (stream wrappers)
- and also some of the new D7UX features
Fact is: All of those introduced new @todos, and for good reason. Contributors and maintainers were and still are able to understand whether there are open @todos left, and decisions can be based on that. It is much better to know about a missing or wonky piece of code than to not know anything. Which also helps in the peer-reviewing process, because it clarifies that a patch author already considered a possibility, but the code can be improved in a follow-up patch.
Lastly, most of the @todos are indeed tackled and tried to be resolved afterwards. So there is not too much to worry about here.
We don't write perfect code. We always improve status quo.
Comment #9
jhodgdonFine, but they don't belong in the doc header. Any IDE (or a quick grep) can easily find @todos in the code.
Comment #10
Crell commentedWhy shouldn't they be in the doc header?
@todo This is a poor implementation, but it works for now. Make it faster later.
@todo Remove this method after we've converted everything over to the new approach.
(I think I used the latter in DBTNG on several methods, actually.)
Comment #11
jhodgdonI may not be completely against @todo notes being in the code (as opposed to doc headers) in HEAD. I can see a possible value during the dev cycle, as they may give people a clue what's coming.
But I definitely don't think they belong in a real release (e.g. 7.0 vs. being in HEAD), since they'll never be fixed at that point in all likelihood. And then they're just saying "This was a bad idea but it's in the code anyway, and we never got around to fixing it, so that's life." Things like that give the impression that Drupal is held together by rubber bands and is about to fall apart, and don't really add anything to programmer documentation, in my opinion, once the product is released, because they're not really the "To Do" list, they're the "We didn't do it right" list.
And given how little interest and attention just about everyone except me has for documentation, I am concerned that if they are put in doc headers now, they'll still be there when 7.0 is out. I would like to avoid that, so am advocating that we don't put them in now, and instead discuss code issues in the issue queue.
Comment #12
Crell commentedGiven that DBTNG was over half code comments before it even went in, an issue you were not involved in, I challenge your assertion that no one cares about code comments but you.
Drupal 6 shipped with @todo comments in it, such as "this is ugly because we have to do it this way in PHP 4. Fix it in PHP 5." We survived, and no bits were harmed in the making of all of those Drupal 6 web sites.
Well then we'd at least have accurate marketing. :-) We're an open source project. If we have pieces held together by rubber bands, we should own up to that and document where the rubber bands are. If @todo is the most appropriate way to do that, so be it. It's also a very clear place for someone to jump in and do the to.
Really, I think you're making too big of a deal out of this. @todos are not harmful. And they're not somehow horribly embarrassing in a docblock but not embarrassing inline. All of software development is one long list of to-dos. If we didn't have them, we would stop writing code. :-)
Comment #13
jhodgdonOK.
Comment #14
sunComment #15
jhodgdonWhat are our coding standards? Are they supposed to be one line, or are they paragraph-style doxygen directives?
Comment #16
sun"Mixed." The current rules for @todo are derived from real world examples and real world problems.
All valid:
The reason for indenting any subsequent lines still belonging to the @todo is that there are cases in which a @todo may be followed by another comment, not belonging to the @todo:
(the same can happen in a function docblock)
And of course, the indentation is consistent with our other coding standards around Doxygen directives.
Comment #17
jhodgdonSee: http://www.doxygen.nl/commands.html#cmdtodo -- officially @todo is a paragraph-style declaration. We can't really have it both ways, at least in doxygen headers -- either a @todo is going to create a paragraph with a header (like a @param, @return, or @see does now), or it isn't (like @code, which can be used in-line, and the HTML-type of things in Doxygen, which maybe the API supports and maybe not). Doxygen has @todo as a paragraph, and we should follow its standard.
The consequence of that would be that you can't use @todo within a @param, @return, etc. It needs to be its own section, the same way we can't use @see in the middle of a @param, because it generates a See Also section on the page, and you don't want a section header in the middle of the Return Value or Parameters section.
So we should probably adopt a standard that in Drupal, @todo in doxygen headers should go at the bottom of the doc header. Thoughts?
There are a couple of places where you've used @todo in the middle of @param declarations in your patch, so those need to be revised.
Comment #18
sunHm. You're right that it's probably not a good idea to use @todo within another directive. But then again, how can we put @todo notes inline?
Technically, I think that this is one of the situations where we can diverge from Doxygen -- primarily because we have and use our own parser. After all, I don't see why we should limit ourselves to something, just because some external tool, which we do not use, is limited.
However, in the same way we can use @see where it makes most sense in the context of the surrounding docs, we should definitely not force a certain location for @todos.
Comment #19
jhodgdonI don't think so... I think @todo items will be displayed, like @see items, as header/paragraph.
Comment #20
jhodgdonSo.
Let me clarify a bit. We need to define the standard for docblocks and for what the API module should do with @todo. I think our two choices are:
a) @todo is a paragraph-style element (doxygen standard). It should be at/near the end of a doxygen docblock, and it will be displayed by the API module as a "To Do" section. It can't be within a @param or @return.
b) @todo is an in-line element. In which case, it needs to have @endtodo with it, and we need to figure out how it would be displayed, because making a To Do header wouldn't make sense in this case.
I have no idea about the display in (b) -- I don't actually think it's workable, but if someone comes up with a viable plan that makes sense for both parsing and display, and that allows inline @todos within @param and @return sections, that's OK with me. I just don't think you can have it both ways, and I think if you have it be inline (the way @code is), so it can be within @param/@return, then you have to have an @endtodo to define where the end is. I think this would be cumbersome, to say the least.
Comment #21
Crell commentedI'd much rather have @todo as a paragraph-level element. I am pretty sure that's how PHPDoc uses it as well. There's no good reason for us to diverge from the industry standard.
Comment #22
jhodgdonSee #17. Doxygen standard is most certainly that it is a paragraph element.
See #18 for sun saying maybe we should diverge from that standard.
Comment #23
Crell commentedSee #21 for me saying that PHPDoc (which is not the same as Doxygen) also uses it as a paragraph-level tag as far as I am aware.
See #21 for me actively disagreeing with sun on that point. :-) Ideally I'd like to see us drop our custom bastardized hybrid document parser and use the one that the entire rest of the PHP universe uses, PHPDoc.
Sometimes "because everyone else does it that way" really is a good reason.
Comment #24
sunNote that I agree as well. :P ;)
@todo forms a new paragraph. The only question is what to do if you need to inject a "@todo-alike" thing into another directive/paragraph. Though we can defer that to a separate issue, or just ignore it entirely.
I realize that my last follow-up wasn't really clear. Especially the last paragraph should have been separated more from the rest... in short: @todo items should be allowed anywhere (well, just not within other paragraphs), similar to the usage of @see statements. Both heavily depend on the directly related context below or above them.
Comment #25
Crell commented@sun: Ah, you mean @todo should be a paragraph-level element but don't bother with a required order within the docblock? I'm +1 on that.
Comment #26
jhodgdonOK, but can we at least suggest that @todo be put at the bottom, if it doesn't need to be somewhere else for context? Like @see and @ingroup, if it pertains to the whole function, I think the best place is at the bottom.
Comment #27
Crell commentedI don't think it really matters either way; same for @see and @ingroup. Honestly I've usually put those above the other @directives, but I don't care strongly one way or another.
Comment #28
sunSure, if not related to any context, then @todo items should ideally be placed at the very bottom of a docblock. Keeps them out of the "regular" documentation, and most often, a @todo relates to the function body, so good to have it as close as possible in that case.
So, what needs to be updated?
Comment #29
jhodgdonThat looks mostly OK...
We should also mention:
- A blank line should be left between other paragraphs (including other paragraph @directives like @param and @return) and one or more @todo paragraphs that are placed together.
- @todo paragraphs should go at the bottom of a docblock if not pertaining to something specific elsewhere in the docblock.
- @todo will generate a To Do section in the doc wherever it is placed.
- It cannot go within a @param or @return.
I'm not sure if we need to enforce the blank line in // comments, since it's not going to be parsed by the API module there?
We should also verify that @todo generates a To Do section in the latest API module, or file an issue to get that added if not.
Comment #30
sunMostly cool with that.
Though the blank line between multiple contradicts our general rule:
There's no reason to enforce a blank line between multiple @todos. Of course, there should be a blank line between a @todo and other statements.
Lastly, we shouldn't mention todo-lists as long as there are none. API module doesn't parse them correctly currently, and also doesn't group them into actual todo lists (which would additionally require to build back-reference mappings). Hopefully, the API module rewrite will ease this, but as of now, changes to API module are pretty much vaporable until the rewrite to use PGP or whatnot has been completed.
Comment #31
jhodgdonAgreed, no blank line between consecutive @todos. I didn't mean to imply that, and if I did it was a mistake.
Is there an issue on the API module to get them to do something with @todo? If not, I doubt it will happen. The parser has been redone, AFAIK, (not on a.d.o yet, but working) and they can probably do this. And if we're going to have @todo in the doc headers for D7, then we need to get this into the a.d.o that will support D7, don't we?
We should for the time being say in the coding standards doc in the meantime that "@todo directives are meant to represent To Do lists, and they'll eventually generate them .... " or something to that effect. I think we want to give folks the idea of what it's supposed to do, because otherwise we're going to get tons of issues in the doc queue saying there are scattered @todo things showing up on api.drupal.org, and I wont' have anywhere to point them to say it's a known issue. Sigh.
Comment #32
jhodgdonReviving this. The API module still does nothing with @todo, as far as I know, and we still haven't updated the standards doc.
Comment #33
sammyd56 commentedWhere did we get with this? Does the API module now generate todo lists?
Comment #34
jhodgdonNo, the API module still does nothing with @todo.
Comment #35
effulgentsia commentedSmall @todo cleanup in #1593696: Fix capitalization in and remove colons from @todo statements within core/lib. Please comment there if something there contradicts decisions reached here.
Comment #36
jhodgdonIt seems like the discussion here was pretty much just clarifying our de-facto standards, so I went ahead and updated
http://drupal.org/node/1354#todo
Marking fixed unless someone wants to reopen with more suggestions.