Search code examples
coldfusionboolean-operationsimp

When to use IMP operator in ColdFusion?


Implication: The statement A IMP B is the equivalent of the logical statement “If A Then B.” A IMP B is False only if A is True and B is False. It is True in all other cases.

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec09d55-7ffc.html

I can vaguely remember what is an "implication" from college. When to use IMP operator in the real world?


Solution

  • After I applied my google-fu

    Found this: http://www.cfug-md.org/meetings/RichardBierregaardLogicwCFConditionals.ppt

    and it inspires me to find out that IMP might be useful for writing unit test:

    assertTrue(Income >= 200000 IMP TaxRate == 0.35);
    assertTrue(Income < 200000 AND Income >= 70000 IMP TaxRate == 0.28);
    assertTrue(Income < 70000 AND Income >= 35000 IMP TaxRate == 0.20);
    assertTrue(Income < 35000 AND Income >= 15000 IMP TaxRate == 0.10);
    assertTrue(Income < 15000 IMP TaxRate == 0);
    

    instead of

    if (Income >= 200000) assertTrue(TaxRate == 0.35);
    if (Income < 200000 AND Income >= 70000) assertTrue(TaxRate == 0.28);
    if (Income < 70000 AND Income >= 35000) assertTrue(TaxRate == 0.20);
    if (Income < 35000 AND Income >= 15000) assertTrue(TaxRate == 0.10);
    if (Income < 15000) assertTrue(TaxRate == 0);
    

    Do you think IMP version is better?