Sean,
I use a UDF called "IsEmpty( )" for readibility purposes. For one thing, to
truly use the len( ) statement (with or without the "IS 0"), you may often
be required to trim the variable - especially if it's user input. This
results in:
<cfif trim(Len(somvar)) IS 0>
</cfif>
..which isn't terribly readible. Instead I use this function:
function IsEmpty(item){
IF(len(trim(item))) return false;
ELSE Return true;
}
Then my code reads:
<Cfif IsEmpty(SomeVar)>
</cfif>
-mk
-----Original Message-----
From: Sean A Corfield [mailto:sean@;corfield.org]
Sent: Monday, November 11, 2002 9:52 AM
To: CF-Talk
Subject: Re: Booleans
On Monday, Nov 11, 2002, at 05:56 US/Pacific, Jeffry Houser wrote:
> bad practice to me. I do see it often enough, such as checking for the
> length of a string like this:
>
> <cfif Len(MyString)>
> Whatever
> </cfif>
>
> It annoys me, because I would much rather see:
>
> <cfif (Len(MyString) is 0)>
> Whatever
> </cfif>
>
> The second is much more readable, in my opinion.
And you reinforce my point by making exactly the error I highlighted:
your two conditions are the opposite of each other.
I agree that explicitly comparing integer expressions to an integer
makes it clearer. We both find the first condition harder to read (I
look at it and think "if len(myString) is true? what does that mean?
ah, yes, myString is not empty") whereas the second expression is much
clearer (in this case saying "if length of myString is zero, i.e.,
myString IS empty"!).
The long-hand expression just gets a little dangerous when you compare
'expr' against 'true' (for the reasons stated - 'expr' might yield 2
which is not equal to true!).
BTW, the isXxxx (or hasXxx) notation is just about the only naming
prefix that I feel makes code more readable and (I believe) it is
mentioned in the WTG Coding Guidelines I published. To me (and my
team!) it's all about making the code read like English. "if (
isEmpty(myString) ) ..."
"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
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm