Are True and False equal to Yes and No when defining argument / attribute values ​​in terms of functionality and performance?

Are there any known functional or operational differences when using yes | no vs. true | false? The ColdFusion documentation states that attribute values ​​of type boolean are specified using yes / no. For example, <cfargument required = "yes | no" ....> I used true and false instead of yes | no and did not see unexpected functionality.

[EDIT] I appreciate the answers, maybe I think a little more general in this case.

The ColdFusion documentation says that the expected value is "yes | no" for some parameters, such as cfargument required . Any idea why yes | no is documented as the only expected value, not true | false or say "any boolean"? It seems a bit ambiguous so as not to indicate any logical type, and not just the yes / no state if either A). We must assume "any logical" B). Actual performance difference. Thoughts?

+4
source share
4 answers

"yes/no" - the number of characters is less.

"true/false" (and true / false) is more consistent with other programming languages.

In terms of performance, they are all related to CF. Until you try to use them in conditional logic, they magically change to other data types, such as java.lang.Boolean. Converting strings and Boolean elements and vice versa is very fast. This is what CF does most of the time. It will be difficult for you to find any reliable tests proving one faster than the other.

For convenience and readability of the code, it is best to stick with one or the other.

Some legacy CF tag features specifically require yes / no. They simply will not work with true / false. I believe this is not the case in CF9 +.

Do not rely on ColdFusion documentation, accurate or current. Almost all methods that list yes / no as default / allowed values ​​actually support any boolean value. "yes / no", "true / false", true / false, 1/0, etc.

IMHO, using yes / no for booleans, crazy. Backward compatible with the old CF5 era. It sucks that Adobe is still using it to output java Booleans.

eg. writeDump( var: (not true) ); gives you NO. But I wanted false ?! Hmm

You can specify which java class your variable represents by calling myVar.getClass().getName() . You can use it to watch CF transfer your data from Boolean to String and return to Boolean again, for example magic.

+5
source

ColdFusion evaluates yes / no, true / false, 1 (or any nonzero number) / 0 equally. This makes it easy to create boolean keys, such as <cfif myquery.recordcount> or <cfif len(FORM.myVar)> , without having to convert the integer to true / false.

+9
source

As an experiment, you can try this. For me, ten million repetitions without using yes resulted in less than 100 milliseconds in most cases.

 <cfscript> bln = true; starttime = getTickCount(); for(i=0;i<10000000;i++){ if(bln eq true) foo="bar"; } writeOutput(getTickCount()-startTime & '<br />'); starttime = getTickCount(); for(i=0;i<10000000;i++){ if(bln eq "yes") foo="bar"; } writeOutput(getTickCount()-startTime & '<br />'); </cfscript> 
0
source

We just upgraded the project to CF2016 and unexpectedly started getting java.lang.VerifyError "Incompatible argument for function" errors. It turned out that in cfform we used available = "true". Changing the value to yes does not resolve the error. Removing the entire “accessible” form tag does. Instead of figuring out what the Flash-related nightmare is, we removed it from our forms.

Thanks Adobe.

0
source

All Articles