I've been playing around a lot with CFCs and looking at other peoples code
and on one point, I'm not sure quite which is more acceptable or better
practice... I have my own preference but I'm interested to find out which
approach I *should* be using so, the question is... 

Which of the examples below is it better and why?

Now before you go off and answer my question, I already know that instance
is simply a struct bound to the variables scope of the CFC so method A is
possibly adding a very tiny overhead whilst CF searches the scopes for the
instance var when it is accessed and all those lookups could add up on a
very busy site but I think that is negligible. 

Above and beyond that, I'm really undecided as to which is the better of the
two...

Also, if there is something better again, then I've not come across it so if
there are alternatives to these two techniques, what are they and what are
their benefits?

A)

<cfcomponent ... >
<cffuntion name="init" ...... >


<cfset instance = StructNew()>
<cfset StructInsert(instance, "dsn", "myDB")>


</cffunction>

<cffuntion name="myFunction" ...... >

<cfquery datasource="#instance.dsn#">

</cfquery>
</cffunction>

</cfcomponent>

OR

B)

<cfcomponent ... >

<cfset variables.dsn = "myDB">

<cffuntion name="myFunction" ...... >

<cfquery datasource="#variables.dsn#">

</cfquery>

</cffunction>

</cfcomponent>



Paul



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:250480
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to