jeffcoughlin.com

ColdFusion's Evlauate() Function

Lately I've been doing my best to use coldFusion's Evalaute() function less and less (due to all of it's performance issues). I have only found one case so far where I haven't gotten away from using it (and I'm pretty sure that there is a way around taht as well).

A friend recently noted that I was setting dynamic variable names using the Evaluate() function. He noted that I should be using the setVariables() function instead (because its faster). Sounded good to me at the time.

Today I discovered that as of CFMX this function is "no longer required in well-formed ColdFusion pages" (I'd almost venture to say Deprecated, but the CFMX docs didn't say that). You can read more about it on the Macromedia Live Docs.

So what do you replace it with? Believe it or not you can just set the new variable name using quotes.

New Way:
<cfloop index="i" from="1" to="5">
  <cfset "myVar#i#" = i />
</cfloop>

Old Way:
<cfloop index="i" from="1" to="5">
  <cfset Evaluate("myVar" & i & " = " & i) />
</cfloop>

Not only is this much faster, but it is much easier to read when we start getting into more complex algorythms on the right-hand side of the set statement.

*** Comments *** (*** Comment Moderation is enabled. Your comment will not appear until approved. ***)
Jared Rypka-Hauer's Gravatar Oddly enough, I JUST posted an entry on this very subject...


http://www.web-relevant.com/blogs/cfobjective/inde...


Freaky how thoughts parallel eachother in any given group of people, no?

Laterz!
#1 by Jared Rypka-Hauer | 3/17/05 2:10 PM



BlogCFC 5.9.8.007 by Raymond Camden | RSS | Contact Blog Owner