Still not too clear with cfif NOT
Someone told me long time ago that it is better not to use <CFIF SomeVariable NEQ ""> which I have used a lot in my codes
It is much better when using <CFIF NOT SomeVariable> instead
Am I remember this correctly?
Someone told me long time ago that it is better not to use <CFIF SomeVariable NEQ ""> which I have used a lot in my codes
It is much better when using <CFIF NOT SomeVariable> instead
Am I remember this correctly?
Are you wishing to discuss the merits of <cfif something NEQ ""> versus <cfif NOT something EQ "">
OR
Do you wish to discuss the merits of <cfif something> versus <cfif something = ""> versus <cfsomething EQ true> etc.
----------
The former is largely style choices and I know of no preformance reason to choose one or the other.
The latter depends a bit on the nature of the variable. If the variable is a true boolean and would have a value of true or false, then I see litte difference between <cfif aBoolean> and <cfif aBoolean EQ true>. Some do argue that the latter is a bit more explicit on what the intention is. The only danger with counting on the variable being a boolean is that ColdFusion is typless and it is possible that a variable one expects to be a boolean got redefined somewhere along the way and is something different.
If the variable is not a boolean then ColdFusion is going to try and cast it as one if you just do <cfif aVariable>. The danger here is that it may cast it in a way that the programmer did not anticipate. Empty strings and numeric 0 will consitstantly be cast as false. But it could be dangerous to count on this. I think the general consensus is to be clear about what you intend and to define what is or is not a true or false condition.
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.