Cryptic sequences in comments

Idlelib has 36 uppercase whole-word 'XXX’s and 34 'TODO’s (not counting colorizer ‘TODO’ tags). Most of the ‘XXX’ tags are inplied (soft?) 'TODO’s, with ‘should’, ‘could’, ‘would’, ‘ought’, ‘check’, ‘decide’, or even ‘TO DO’. Some are mine, most not I think.

3 Likes

According to GitHub code search, the string “XXX” appears in more than 2 million C files. According to the first result pages, this seems to be mostly in comments to flag questions, warts and gotchas.

The Python codebase is not really an outlier in this regard.

3 Likes

I would recommend not going through the code and removing XXX. That’s like a hit-and-run code cleanup change that we discourage. We should recommend it not be used in future code, since obviously some people are confused by it. To me, it means something like NOTE. The main advantages is probably that it’s easy to type, easy to search for and also stands out.

8 Likes

I looked around a bit more and found that XXX is a way of calling out for attention: it’s the morse code version of Pan-Pan. In other contexts it is used as a wildcard, e.g. when referring to sets of symbols as in .fetchxxx().

2 Likes

If you don’t want to see more XXX comments checked in with code: add a check to our make patchcheck CI step that blocks merging when newly added/changed lines contain one. The error message should recommend people use TODO, referencing a filed Issue# when deemed appropriate. Nobody is likely to meaningfully object to such a check. With that in place, the number will slowly trend downwards over time. :slight_smile:

Some noteworthy widely used style guides go further and effectively require the issue be referenced in the comment such as Google’s Python & C++ guides - I don’t think we have a reason to go that far in CPython (but I wouldn’t object if consensus says “do it”).

Regardless, I recommend not worrying about existing XXXs in the codebase. At a glance via grep there appears to be ~1500 of them in CPython main.


Yet another explanation the history of XXX elided given: Questioning XXX is not a new question or conversation. It has happened multiple times before in other forums for other projects per some quick Google searches. What is the meaning of #XXX in code comments? - Stack Overflow being a typical canonical reference. Lending support to the idea of just not using XXX in new code.

6 Likes

Yeah, a CI check sounds good to me. The discussion history clearly shows that the meaning of XXX belongs to the code writer, not the reader; it does not add value to a comment.

Of course not; that goes for all style suggestions, both PEP-7 and PEP-8.

2 Likes

In that case, I think using ATTENTION would be much more clear.

I certainly wouldn’t interpret XXX as meaning anything in particular, unless it were “this comment contains pornography” or “this comment contains an old-timey jug of prohibition-era bootleg alcohol”.

4 Likes

Look, I know there’s weird and bad code out there, but if ever an IDE or programming language allows you to donate moonshine to the subsequent maintainers, it will be an instant success…

Personally, I’ve never used the XXX convention, largely because of these ambiguities. I’d rather write FIXME, TODO, or NOTE, or sometimes HACK (which overlaps with some of the use of XXX here, I think? it’s acknowledging that something is hacky and disgusting, but working).

1 Like