4

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?

Henry
  • 32,689
  • 19
  • 120
  • 221

3 Answers3

2

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?

Henry
  • 32,689
  • 19
  • 120
  • 221
1

In the real world, it would be handy to be able to do something like this, to perform validation on optional params:

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

Wherein we only care about validation of URL.a if it exists. That'd be about the most useful application of IMP, IMO (well, like, it would be).

However due to a bug in the implementation of IMP, this doesn't work :-(

I think Dale's assertion that the much longer (and incorrect) logic is easier to read than the shortened version is self-evidentally wrong, and based on a specious premise to boot. His position is based on an idea that "someone not knowing something" is a continuous state, ie: when someone doesn't know something (like what "IMP" means), then they will forever not know it. This is not true. A person might not know something initially, but once they find out about it, then they will know about it. So the problem of not knowing how the IMP oerator works is a very short-lived one.

I don't think situations arise wherein IMP is needed arise very often, but it's handy to have it there. And it'd be handier still if it worked properly ;-)

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
  • Thats not what Im asserting, Im suggesting that clear code is far superior to convoluted code that 99% of developers won't understand. – Dale Fraser Nov 21 '11 at 23:34
  • @Dale, 100% of developers won't understand a technique/concept/syntactical element until it's presented to them. Then once presented to them, they generally *will* understand it. Yours is still a specious position: you simply can't assert that your logically-wrong example is better than the correct example using IMP. Unless your attempt of translating the IMP expression into a different expression is a case-in-point of how it's hard to understand, I guess..? I grant you people might not know about the IMP, operator, but if they come across it they'll look it up! – Adam Cameron Nov 22 '11 at 00:07
  • I think you should read again the purpose and intent of the tag. Your argument is more futile than mine, your saying just because its there people should use it and people will look it up if they don't understand, that is like me using a word in this sentence that no one understands and making everyone look it up when there is a better clearer word that everyone would understand. We will agree to disagree. – Dale Fraser Nov 22 '11 at 02:54
0

I think you should stay clear of it, I've never seen it used and never had a need to use it. Other developers mostly wont understand what it is or means.

I would rather write

<cfif a eq true and b eq false>

than

<cfif a imp b>

The first is much clearer.

Dale Fraser
  • 4,623
  • 7
  • 39
  • 76
  • 2
    (a IMP b) is actually (NOT a OR b) - http://www.cfug-md.org/meetings/RichardBierregaardLogicwCFConditionals.ppt – Henry Nov 08 '11 at 01:32
  • [Adam is right](http://stackoverflow.com/questions/8043999/when-to-use-imp-operator-in-coldfusion#8048119) - if you only ever write code for inexperienced developers, you'll only ever have inexperienced developers writing your code. It is _far_ better to code effectively, and **educate** developers when they encounter something they don't understand. – Peter Boughton Nov 08 '11 at 13:02
  • I don't agree that using obscure coding that no one understands is a good idea. @Henry I didn't write it like that, if you have your own solution, then propose an answer rather than changing a correct answer to how you would do it. – Dale Fraser Nov 21 '11 at 23:33
  • 1
    @DaleFraser (a IMP b) is actually (NOT a OR b), so using your style of cfif, shouldn't it be ``? – Henry Nov 21 '11 at 23:53
  • Indeed, its nearly an example of how I would write such logic, its not meant to be equilivant. However your proposed model is no clearer than the imp. – Dale Fraser Nov 22 '11 at 03:01
  • @DaleFraser ok, I guess it was because you said you rather write X then Y, and I thought you imply that X is eqv to Y. Nvm, sorry for editing your answer. – Henry Nov 22 '11 at 20:58