Continuing with my fascination with the important things in programming languages — that's right, comment control structures — I have another idea!
Something which is a constant source of annoyance when using block comments is that sometimes you already have a block comment inside the larger area you are wishing to comment out:
doSomething();
if (someCondition()) {
/*
todo: implement
*/
} else {
doSomethingElse();
}
return true;
}
// and now lets say we want to comment out a block of this function:
function foo() {
doSomething();
/*
if (someCondition()) {
/*
todo: implement
*/
} else { // <-- error!
doSomethingElse();
}
*/ // <-- error!
return true;
}
What you get now is a syntax error, and half you block uncommented since the inner block comment's closing control is ending the outer block!
There are a couple of ways I can think of to avoid this issue. (In all of these examples, just ignore the syntax highlighting!)
Indentation-controlled commenting
If there is a /* on a line by itself, then that will only be closed by a */ on its own line at a matching indent level. This one makes the most sense to me, since indentation is used so much in your regular code (and especially if you use Python!), why not apply it to comments?
comment
/*
comment
*/
still a comment
*/
Named comment blocks
Using some special syntax, define a code block with a name. A closing element with matching name will be required to close the block. For example:
comment
/*!bar
comment
bar!*/
still a comment
foo!*/
Comment matching
Just as we match open brackets to closing brackets, why not match open comments to closing comments?
comment
/*
comment
*/
still a comment
*/
Yes, they're mostly half-brained ideas, and the actual implementation of any of these would probably need to choose some special construct to avoid problems with legacy code (eg: use "/*|" and "|*/" for indentation commenting), but anyway, they're just some ideas.