When to use the IMP statement in ColdFusion?

Conclusion: statement A IMP B is the equivalent of the logical statement โ€œIf A then B.โ€ IMP B is False only if A is true and B is False. This is true in all other cases.

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

I can vaguely remember what college โ€œimplicationโ€ is. When to use the IMP operator in the real world?

+4
source share
3 answers

After I applied my google-fu

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

and this inspires me to find out that IMP can be useful for writing a 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

 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 the IMP version is better?

+2
source

In the real world, it would be convenient to do something like this to perform a check on optional parameters:

 <cfif structKeyExists(URL, "a") IMP validateId(URL.a)> 

In this regard, we can only verify the correctness of URL.a, if it exists. This will be the most useful IMP application, IMO (well, it would seem to be).

However, due to a bug in IMP implementation, this does not work: - (

I think that Daleโ€™s claim that much longer (and incorrect) logic is easier to read than the shortened version is, of course, erroneous and based on the premise for downloading. His position is based on the idea that "someone does not know something" is a continuous state, i.e. When someone does not know anything (for example, what โ€œIMPโ€ means), then they will not know this forever. It is not true. A person may not know something initially, but as soon as they learn about it, they will know about it. Therefore, the problem of not knowing how the IMP ionizer works is very short-lived.

I do not think that situations arise in which IMP is required, arise very often, but it is convenient for its use. And it would be more convenient if it worked correctly; -)

+1
source

I think you should avoid this, I have never seen it used and never needed to use it. Other developers usually do not understand what it is or what it means.

I would rather write

 <cfif a eq true and b eq false> 

than

 <cfif a imp b> 

The first is much clearer.

0
source

Source: https://habr.com/ru/post/1380087/


All Articles