The thing is that variables declared with "var" don't exist in any named
scope. That convention in CFCs is totally consistent with the way the var
keyword has worked since the introduction of UDFs in CF5. A function on a
page is another level below the "page" -- so, I think it is, in fact,
consistent with the way the rest of CF works (especially now that the
Variables scope works in 6.1).
Since local variables are resolved first, there is no "searching up the
scopes" for local variables, so there should not be performance
implications.
One convention I've seen, if you really want a "scope" when reading the code
is to do something like:
<cffunction>
<cfset var local = structNew()>
</cffunction>
You can then use local.foo for all your local variables, which would make it
unambiguous when reading the code. I find, though, that it becomes
cumbersome to do things like:
for(local.i = 1; local.i LTE arrayLen(foo); local.i = local.i + 1){}
Generally speaking, when I'm reading CFC code I assume that if the variable
doesn't have a scope it is a local variable -- one of the many reasons you
should always scope your Arguments and Variables variables.
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Bryan F. Hogan
> Sent: Monday, October 06, 2003 8:03 AM
> To: [EMAIL PROTECTED]
> Subject: [CFCDev] Variable referencing in CFCs
>
>
> I've heard that in order for a variable only to exist within a specific
> function that you var scope it. I understand that. However, they also say
> that you don't reference the var scoped variable with the Variables scope
> prefix. And that the variable scope prefix is Global within the
> CFC and not
> just the function.
>
> I understand. But this is different than what is in regular CFML
> pages. Then
> say you have a function with many lines of code and you don't
> reference your
> Variables with the Variables scope, to me this makes the code
> hard to read.
> I have always thought that referencing variables within their
> scope was the
> way to go because 1 CF didn't need to search up the variable scopes and 2,
> it was more manageable. So why then wouldn't regular CFML pages and CFCs
> work the same way regarding the Variables scope?
>
> What are your thoughts on this?
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word '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]