More important than performance, IMO, evaluate() is more often than not both unnecessary and confusing. It's not that any one line of code with evaluate is necessarily hard to understand, but a year or more later when someone else is reading through the code, use of evaluate() is more likely to obfuscate the intended purpose of the code than other more semantically rich constructs (the CFINVOKE example being a clear instance of this).

Evaluate() is over-used in ColdFusion code that I have seen -- it is almost never necessary, and when it is necessary it's often because the underlying structure of things wasn't well thought out -- the times when it's both necessary and appropriate are extremely rare. Thus, use of evaluate() is almost always a sign of someone who doesn't really know how to use ColdFusion or someone who hasn't properly thought through what they are trying to do. Show me code that uses evaluate() and chances are that there is a cleaner, easier-to-read, AND more efficient way to make it happen.






Cody Caughlan wrote:
I figured as much and I would have used cfinvoke myself (this was found during a review of a fellow developer's code). Other than "Evaluate is evil" what kind of an argument can one make? Say you had to persuade your development team to not use Evaluate() bu cfinvoke, what kind of valid, software engineering principles can you refer too? Type safety? Proper encapsulation? (I dont think this is even remotely applicable, but you get my drift...)...

------------------------------------------------------------------------
*From:* [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] *On Behalf Of *Brian Kotek
*Sent:* Tuesday, May 16, 2006 7:38 PM
*To:* [email protected]
*Subject:* Re: [CFCDev] CFINVOKE vs. Evaluate

Use cfinvoke. Evaluate is evil.

Also you're incorrect about the "one-off" usage of cfinvoke. You can call methods against a CFC instance that was already created like this:

<cfset obj = createObject('component','foobar').init() />
<cfinvoke component="#obj#" method=#FunctionName# returnvariable="foo" />

Hope that helps,

Brian


On 5/16/06, *Cody Caughlan* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Hi-

    Is it better to use cfinvoke to dynamically call a method on a CFC
    or to use
    the Evaluate() function?

    E.g.

    Approach A:

    <cfset obj = CreateObject('component', 'foobar').init()>
    <cfset FunctioName = "getName">
    <cfset foo = Evaluate("obj.#FunctionName#()")>

    -- OR --

    Approach B:

    <cfset FunctioName = "getName">
    <cfinvoke component="foobar" method=#FunctionName#
    returnvariable="foo" />

    Other than that Approach A takes an extra line to instantiate the
    object, is
    it better overall to use cfinvoke? One advantage that Approach A has
    for our
    needs is that we are potentially running this in a loop, so we can
    create
    the object once and then put it in a cache struct and re-use it in a
    subsequent loop call, whereas cfinvoke just calls it in a one-off
    fashion.

    Any ideas? (Dont say use ColdSpring...)

    Thanks
    /Cody




    ----------------------------------------------------------
    You are subscribed to cfcdev. To unsubscribe, send an email to
    [email protected] <mailto:[email protected]> with the words
    'unsubscribe cfcdev' as the subject of the email.

    CFCDev is run by CFCZone (www.cfczone.org <http://www.cfczone.org>)
    and supported by CFXHosting (www.cfxhosting.com
    <http://www.cfxhosting.com>).

    An archive of the CFCDev list is available at
    www.mail-archive.com/[email protected]
    <http://www.mail-archive.com/[email protected]>



----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected] ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]



----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to