There is a difference between "local scope" and "local variables scope" which is likely resulting in some confusion. The local scope is what is used inside of a function or CFC and it does not use "variables." in front of the variable name. There is a separate scope called "variables," often referred to as "local variables," where you write "variables." in front of the variable name.
Earlier I thought you were asking about using "variables." in front of the variables scope. If you are asking about the local scope, then yes, you should still define it as being in the local scope, but the reason has little to do with performance and you don't write "variables." to scope it. You define the scope of local variables so that you don't write code in a function that accidentally impacts code outside of the function, which can happen if you don't specifically restrict your variable to being local to a function. This is a common problem and it is absolutely a best practice to identify local variables as being local variables. Not doing so is a coding mistake, and one that is quite common. -Mike Chabot On Wed, May 18, 2011 at 9:59 PM, Eric Roberts < [email protected]> wrote: > > A good question that was brought up by one of our developers. When you > don't scope a var it has to search through the various scopes to find it, > in > order of precedence. If you are using alocal scope, is there a performance > hit if you don't scope it since "variables" is implied or does it still go > into search mode? Also...is this negated of you use a cfset on the top of > the page (again...this is only referring to local vars.) > > Eric > > -----Original Message----- > From: Eric Cobb [mailto:[email protected]] > Sent: Wednesday, May 18, 2011 01:36 PM > To: cf-talk > Subject: Re: scoping > > > Here's my take on it: > > http://www.cfgears.com/index.cfm/2010/9/22/The-importance-of-proper-variable > -scoping<http://www.cfgears.com/index.cfm/2010/9/22/The-importance-of-proper-variable-scoping> > > Thanks, > > Eric Cobb > http://www.cfgears.com > Help me make a difference this summer -http://bit.ly/i8dJvQ > > > On 5/18/2011 11:51 AM, Eric Roberts wrote: > > We had a discussion at work as to whether or not we should scope local > > vars with the "variables." scope since that is implied in a cfset. > > One camp says it is not needed because of the implicit scoping when > > using cfset...the other camp says it is better to tack on "variables." > > and make it explicit for security and readability. Any thoughts? > > > > Eric > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:344649 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

