Computer programming is complicated enough that we really don’t need to look for ways to further confuse programmers. On the contrary, we should actively look for ways to increase programmer understanding. Perhaps one of the easiest ways to confuse programmers is to choose bad names for things. For example, consider this little code snippet that’s supposed to demonstrate using a ManualResetEvent
to control thread execution.
private ManualResetEvent suspended = new ManualResetEvent(true);
public void Main()
{
//
// suspend
suspended.Reset();
// resume
suspended.Set();
//
}
public void Work()
{
// long task
while (!stop)
{
suspended.WaitOne(/* optional timeout */);
//worker task
}
}
There’s nothing wrong with the way the snippet works, but naming the event suspended
is one of the most confusing things I’ve seen this year. The suspended flag is set when the program is running. WTF? I’m pretty sure I’m not the only programmer who, if he were to encounter this in production code, would very likely misunderstand it.
“I have to wait for the suspended
flag to be set before I can resume.”
Come on, people. Think about what you call things. Naming is important!