Negative variable names
barbara_morris 120000DX5W Visits (3860)
I don't know whether it's my own mental defect, or if it's more universal, but I find it awkward to understand code using variables that mean something negative. I find I have to exercise my brain more to understand the first "IF" than the second in the following two snippets of code. My brain freezes up just a little bit when it tries to understand setting notValid to off. But it has no trouble understanding setting isValid to on.
if %lookup(name : validNames) > 0; notValid = *off; else; notValid = *on; endif; if %lookup(name : validNames) > 0; isValid = *on; else; isValid = *off; endif;
The name doesn't have to contained the word "NOT" or "NO" to be awkward. I had a case today where one of our test programs was asking the tester if they wanted to skip part of the testcase. I had a parameter called SKIP that was getting set to '1' or '0'. The calling CL program then had code that looked like this
if (&skip *eq '0') + then(do) do some stuff enddo
I changed it so the parameter and CL variable were called do_it, set to '1' or '0'. Then the CL looked like this, which I found much easier to follow even as I was writing it:
if (&do_it *eq '1') + then(do) do some stuff enddo
Is it just me? Or are the positive forms of the names easier to understand for everyone?