When naming flags, or any variables for that matter, use positive concepts so that the user has easier time reading the code.
But this blog is about coding, so lets get back to the world where ambiguity does not exist... Recently I came across this piece of code (I wish I was making this up) which took the negative question to a new level of confusing. if ( ! information_hiding_disabled) { ... } I don't know about you, but I personally have to think really hard until I can figure out under which conditions this executes. Even knowing what the the value of the flag is, makes it hard to think about what it represents. The issue here is that "information hiding" refers to a negative concept. Adding the word "disabled" to it adds a negation to the concept which I guess makes positive again. Often times, when you actually want to use it in an "if" statement you want the opposite behavior and hence you may need to add "!/NOT" So now you essentially have this: if ( ! ! ! show_information) { ... } Lets look at a loop as a good way to name a flag: boolean done = false; while(!done) { if (...) done = true; } Now lets look at the opposite and notice that it is harder to read: boolean notDone = true; while(notDone) { if (...) notDone = false; } In the second loop the "while(notDone)" is easily readable, but the issue are the assignments, especially the exit assignment "notDone = false" Here again, double negation is going on and it takes my brain just a little longer to figure out what "false" means in this case. Furthermore there may be an "if" statement which would make it worse. if ( ! notDone) So in conclusion don't ask negative questions! Variables/flags which are named with positive concepts are much easier to read than variables which represent negative concepts. Please think about this when you write your code. Otherwise, I get a headache. |