Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are True and False equal to Yes and No when specifying argument/attribute values in terms of funcationality and performance?

Tags:

coldfusion

Are there any known functional or performance differences in using yes|no vs. true|false? ColdFusion documentation states that values for boolean-type attributes are specified with yes/no. For example, <cfargument required="yes|no" ....> I have used true and false in place of yes|no and have seen no unexpected functionality.

[EDIT] I appreciate the responses, perhaps I am thinking a bit more general in this case.

ColdFusion documentation states that the expected value is 'yes|no' for some parameters, such as for cfargument required. Is there any insight into why yes|no is documented as the only expected values, rather than also true|false or stating 'any boolean value' is expected? Seems a bit ambiguous to not indicate any boolean type rather than only state 'yes|no' if either A)We are to assume 'any boolean' B)There is an actual performance difference. Thoughts?

like image 713
David Avatar asked Aug 08 '12 13:08

David


2 Answers

ColdFusion evaluates yes/no, true/false, 1 (or any non-zero number)/0 equally. This makes it easy to make shortcut booleans like <cfif myquery.recordcount> or <cfif len(FORM.myVar)> without having to convert the integer into a true/false.

like image 196
Sharondio Avatar answered Sep 26 '22 08:09

Sharondio


"yes/no" is a few characters less to type.

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

In terms of performance, they are all strings as far as CF is concerned. It is not until you try to use them in conditional logic that they magically change into other data types, like java.lang.Boolean. The conversion between strings and Booleans and back again is very fast. It's what CF does most of the time. You'd be hard pressed finding any reliable tests proving one faster than the other.

For code maintainability/readability it's best to stick with one or the other.

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

Don't rely on the ColdFusion documentation being accurate or up to date. Almost all of the methods that list "yes/no" as the default/allowed values actually support any kind of boolean value. "yes/no", "true/false", true/false, 1/0, etc.

IMHO using "yes/no" for booleans is crazy. Backwards compatibility from the old CF5 era. Sucks that Adobe are still using it to output java Booleans.

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

You can tell what java class your variable is currently by calling myVar.getClass().getName(). You can use it to watch CF casting your data from Boolean to String and back to Boolean again, like magic.

like image 40
Mike Causer Avatar answered Sep 26 '22 08:09

Mike Causer