The obvious answer – to stop it from executing – begs the further questions: Why should the code not execute? Did it ever execute? Will it ever execute? There are several possibilities:
These are all reasons for turning code into comments, some more reasonable than others. Categorising our examples: Example 0) appears to be silenced debug, Example 1) work in progress, and Example 2) a hacked-up experiment – though we really cannot be sure. Example 2) might equally well remove the symptoms (if not the cause) of a bug and Example 1) might represent a superceded method.
The important point is that unless the author of the commented-out code explains what's intended, it is impossible for future readers to accurately guess. How, then, should the author explain? With a comment!
for (Surfaces::iterator sf = surfaces.begin();
sf != surfaces.end();
++sf) {
// std::cout << "Drawing: " << *sf << "\n";
// Work in progress. Surface stream output not yet implemented.
// Tom Guest, 12-Dec-2003.
sf->draw();
}
Depending on circumstance, the comment might read:
// Do not inflict verbose debug output on everyone.
// Tom Guest, 12-Dec-2003.
or even:
// Commenting out the above line of code appears to cure the
// random crashes reported as PR666. I am not yet sure why,
// but am leaving the code commented out while I investigate.
// Tom Guest, 12-Dec-2003.
I have included an explicit name and date in the comment – redundant data, strictly speaking, since they duplicate information held in the source management system – because I do not intend the code to persist in its current state. The comment has a sell-by date. Anyone reading it will immediately understand what's going on and who to hassle if they don't like it.
Copyright © 2004 Thomas Guest |