Evaluate is an expensive function to execute. It also tends to be difficult to read, depending on how complex the evaluation is. Finally, its use can almost always be avoided, so using it despite its shortcomings can been seen as a mistake akin to using unnecessary pound signs.

On 5/17/06, Cody Caughlan <[EMAIL PROTECTED]> 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]> 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] 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]

----------------------------------------------------------
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