[thelist] Friday Freebie

jeff jeff at members.evolt.org
Wed Dec 27 01:08:22 CST 2000


raymond,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Raymond Camden
:
: Well, certainly, in cases where you can require input,
: you should.  For example, custom tags, but there are
: many example of cases where you can't always be
: sure you will have the correct input. The example I
: used in my email, a 'details' page, is a perfect example
: of that. When it comes to readability, to me, this is much
: better:
:
: <CFIF NOT IsDefined("URL.ID") OR NOT IsNumeric("URL.ID")>
: 	<CFLOCATION ...>
: </CFIF>
:
: compared to:
:
: <CFTRY>
: 	<CFPARAM NAME="URL.ID" DEFAULT="0" TYPE="Numeric">
: 	<CFCATCH TYPE="Any">
: 		<CFLOCATION ..
: 	</CFCATCH>
: </CFTRY>
: <CFIF NOT URL.ID>
: 	<CFLOCATION ..>
: </CFIF>
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

i've already posted this code sample, but what about this?

<!--- is it a number and not zero? --->
<cfif NOT Val(url.id)>

  <!--- it is not a number or it is zero --->
  <cflocation url="#cgi.script_name#" addtoken="no">
  <!--- /it is not a number or it is zero --->

<cfelse>

  <!--- it is a number --->
  <cfquery name="blahdetails" datasource="#dsn#">
    SELECT blah
    FROM table_name
    WHERE id = #Val(url.id)#
  </cfquery>
  <!--- /it is a number --->

</cfif>
<!--- /is it a number and not zero? --->

all the code you have above with the try/catch scenario is completely
unnecessary because the cold fusion server will not throw an error when you
try to param a value.  if it's already defined (coming in from a form post,
through the url, or already defined in a previous template in the same
request then it simply ignores the param and works with the value that's
already defined.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: You could also say CFLOOP isn't necessary (just
: write your code constructs N times :), but you
: certainly should use the tools you have at hand.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

i don't think that's a fair comparison because there are instances where the
use of cfloop is unavoidable.  as an example.  you have a form that allows a
user to determine how many files they want to upload.  this page posts to
itself and seeing the count the user is requesting then loops from 1 to the
count creating uniquely named file upload form elements.  this isn't an
instance where you could do it any other way than with cfloop.

you're right though - maybe it's just personal taste.

thanks,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff at members.evolt.org





More information about the thelist mailing list