On Saturday, Nov 9, 2002, at 15:10 US/Pacific, Dave Watts wrote:
> Pedantry can be dangerous. While Len returns an integer, CF treats
> non-zero
> integer values as boolean "true" values when they're used in boolean
> expressions.
Yes, so does C and C++ but that doesn't make it good style, IMO.
> Now, you may argue that your explicit syntax is more readable, but I'd
> counter that by saying that any competent CF developer should know that
> integers are treated as boolean values.
As would any C or C++ developer. Again, it doesn't make it good style.
I prefer <cfif len(x) gt 0> as an explicit test although I probably
wouldn't take a developer out and shoot them for just writing <cfif
len(x)>. I *would* take them out and shoot them for writing <cfif not
len(x)> which I think is a horribly ugly and easily misread condition!
<cfif len(x) eq 0> is *much* clearer. I've seen many 'non-programmers'
write the equivalent of 'not len(x)' when they really mean something
like 'len(x) ne 0'! My motto is: be explicit.
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.
Note 2: don't write this sort of thing either:
<cfif somecondition>
<cfset x = 1>
<cfelse>
<cfset x = 0>
</cfif>
Think about that... you really mean this, don't you:
<cfset x = somecondition>
(and then treat 'x' as a boolean)
The following seems a more common version of that:
<cfif somecondition>
<cfset y = false>
<cfelse>
<cfset y = true>
</cfif>
Why not:
<cfset y = not somecondition>
"SOAP is not so much a means of transmitting data
but a mechanism for calling COM objects over the Web."
-- not Microsoft (surprisingly!)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm