I always find IF/Else easier to read than a lengthy nested function. I always find myself counting parenthasis :)
As far as returns - as long as it's very short function I could care less. If the function is many lines of script, multiple returns make it more difficult to trouble shoot (IMO). -mk -----Original Message----- From: S. Isaac Dealey [mailto:info@;turnkey.to] Sent: Monday, November 11, 2002 10:47 AM To: CF-Talk Subject: RE: Booleans function isEmpty(mystring) { return yesnoformat(not len(trim(mystring))); } function isNotEmpty(mystring) { return yesnoformat(len(trim(mystring))); } Sure, it's niggling, but I suspect this would be more efficient for the server. For me it's actually easier to read these than a function with an if-else in it. Incidentally -- I'm never personally bothered by a function with more than one return statement. It's like putting <cfexit> in a custom tag. But then, I may not be "a lot of developers". ;) S. Isaac Dealey Certified Advanced ColdFusion 5 Developer www.turnkey.to 954-776-0046 > Which isn't bad, but ... I think a lot of developers would cringe at the > double 'returns' in there. > function isEmpty(item){ > var toReturn = true; > if(len(trim(item)) GT 0){toReturn = false;} > return toReturn; > } > ~Todd > On Mon, 11 Nov 2002, Mark A. Kruger - CFG wrote: >> 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 This list and all House of Fusion resources hosted by CFHosting.com. The place for dependable ColdFusion Hosting.

