Suppose that you see the following pattern in code:
function foo() {
...
var someFlag = false; // Until contested
for/while/if () {
...
// Possibly deeply nested in some non-trivial logic
someFlag = true;
...
}
if (someFlag) {
// Additional processing of some sort
}
...
}
With no further description, do you have a good idea of what that "until contested" comment is trying to describe? Do you think it would be a helpful comment in understanding code you were reading?
It's describing a boolean flag which starts off as being set to one value, until some later point(s) when it may switch to the other value but, not back once it has been set. Common uses: "found" / "completed" / "did change something" etc...
Do you have any way that you prefer to describe said pattern of code? "Until contested" is the most concise / clear way that I've found to quickly tag it in my own code for ease of reading in cases that don't really warrant a more detailed comment. I'm wondering if it would be a reasonable comment to use in code I write on a team professionally too.
someFlag
is exactly an example of bad choice of name. OP has mentioned some good choice of names in the spoiler section; please mouse over to read it. The name needs to explain its own raison d'etre.someFlag
fails to hint strongly that its initial value is not its final value (i.e. it doesn't distinguish itself from a local immutable value). The other good examples, however, strongly hints that they are some values to be determined. Any not-so-silly programmer could reason that the value is going to be computed soon. – rwong Mar 11 '17 at 00:12