IBM Support

Negative variable names

General Page

You are in: RPG Cafe > Negative variable names

Short URL: https://ibm.biz/rpgcafe_negative_fldnames

RPG Cafe: Negative variable names

Negative variable names

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 that uses variables that with a negative meaning. 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 contain 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 test case. 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?

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SS69QP","label":"Rational Development Studio for i"},"Component":"ILE RPG Compiler","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
16 December 2019

UID

ibm11119285