> The only real reservation I have about that approach is that
> it makes it
> hard to read code without there there being some ambiguity in
> which variable
> is supposed to be referenced.
If you always scope your instance vars (variables.my.varName), never scope
anything else, and are fully encapsulated (or at least explicity scope any
breaks in encapsulation), then there is zero potential for ambiguity. If
it's got a prefix, you know where it's at. If it doesn't, then it's local.
Tracking bugs can be more difficult, because a typo can make the implicit
scopes come into play, but that's something unit testing will catch, because
the environment will be largely devoid of anything in implicit scopes.
> If you always scope everything _except_ arguments and function local
> variables then I think it makes sense, but could still lead
> to unexpected
> behaviour after the code has gone through a few revisions.
Worth reiterating that you can't call arguments unless you explicitly
specify the arguments scope. Any implicit references to the argument scope
are actually references to the local variables scope. Thus you can
introduce nasty bugs:
<cffunction name="factorial">
<cfargument name="num" />
<cfset var i = "" />
<cfloop from="2" to="#arguments.num - 1#" index="i">
<cfset arguments.num = arguments.num * i />
</cfloop>
<cfreturn num />
</cffunction>
What's that function do? If you said computes a factorial, you'd be wrong,
it actually returns the same number. Note that it does NOT create a 'num'
variable in the 'variables' scope. That kind of potential nastiness is why
I never scope argument references, prefering to always use the local copy
(which can't be scoped).
Cheers,
barneyb
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Spike
> Sent: Tuesday, July 20, 2004 5:13 PM
> To: [EMAIL PROTECTED]
> Subject: RE: [CFCDev] Making Persistant CFCs thread safe
>
>
> >Using a psuedo-scope means you always have to dereference
> >arguments using
> >the scope qualifier. Not using it means you can ignore the
> >arguments scope
> >(except for structKeyExists), not scope any local variables,
> >and never have
> >to worry about using the right scope anywhere.
> >
>
> The only real reservation I have about that approach is that
> it makes it
> hard to read code without there there being some ambiguity in
> which variable
> is supposed to be referenced. Given that there are 6 implicit
> lookup scopes
> plus the cfquery loop scope and the function local scope,
> that could lead to
> some errors that are pretty hard to track down.
>
> If you always scope everything _except_ arguments and function local
> variables then I think it makes sense, but could still lead
> to unexpected
> behaviour after the code has gone through a few revisions. On
> the whole I
> think it's relatively unlikely that this would be a big issue in most
> applications though since it's essentially the same issue
> that we've had to
> deal with for years when not explicitly referencing the
> variables scope.
>
> Spike
>
> --------------------------------------------
> Stephen Milligan
> Code poet for hire
> http://www.spike.org.uk
>
> Do you cfeclipse? http://cfeclipse.tigris.org
>
>
>
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> in the message of the email.
>
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.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'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]