I changed the subject because we're way off track from Studio MX (and
have been for several posts).
On Sunday, Nov 10, 2002, at 03:30 US/Pacific, Jeffry Houser wrote:
> At 03:41 PM 11/9/2002 -0800, you wrote:
>> Note: never, ever compare boolean expressions to 0 or 1 (or false /
>> true), especially to 1 (true). <cfif f(x)> is not always equivalent to
>> <cfif f(x) eq true> - precisely because people can be lazy about
>> mixing
>> numbers with real booleans.
> I am completely confused by this.
> What should you compare Boolean Expressions to if not False / True
> or 0 /
> 1 ?
You don't compare them to anything. You don't need to. They are
*already* boolean. You say:
<cfif someBooleanExpression>
You shouldn't say:
<cfif someBooleanExpression eq true>
You say:
<cfif not someBooleanExpression>
You shouldn't say:
<cfif someBooleanExpression eq false>
or
<cfif someBooleanExpression neq true>
I've seen code that explicitly compares expressions to true fail
because the boolean expression relies on the implicit integer->boolean
conversion and returns some arbitrary non-zero for true - whereas the
constant, true, is effectively 1. So comparing <cfif foo eq true> FAILS
even tho' <cfif foo> SUCCEEDS.
This is more than a stylistic issue - this is defensive programming.
> Are you saying that the conditional examples are wrong, or the
> one-line
> examples are more efficient?
Neither. I'm saying that they are better style because they show an
understanding of how booleans really work. They are simpler code - and
simpler code is often more efficient but that's not my primary concern.
Simpler code is often less error prone too.
"I have always wished that my computer would be
as easy to use as my telephone.
My wish has come true - I no longer know how to
use my telephone." -- Bjarne Stroustrup
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Get the mailserver that powers this list at http://www.coolfusion.com