On Wed, May 18, 2011 at 12:51 PM, Eric Roberts
<ow...@threeravensconsulting.com> 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?

I would ALWAYS scope.  Not for "style" reasons, not for readability vs
non-readability, not for speed.  I've run into at least one occasion
when CF choked and died because of un-scoped variables.

In this case it was a long running CF request that used un-scoped
variables.  In walking through the scopes during an isDefined() call,
CF eventually got to the CGI scope, which required CF to make a
request back to the webserver (or webserver connector) to see if such
a variable existed.  Problem was that the connection with the
webserver had already been severed (because it was a long running
request).  So, CF sat and sat waiting for an answer that would never
come.  Eventually these requests would build up, the server would run
out of threads, then it would fall over.  Bam.

It is true that this is a fairly specific case that may not happen to
many people.  However, it does serve to illustrate that YOU NEVER
REALLY KNOW what strange negative side effect unscoped variables might
cause.

So - scope it.  Always.

-Cameron

-- 
Cameron Childress
Sumo Consulting Inc
http://www.sumoc.com
---
cell:  678.637.5072
aim:   cameroncf
email: cameronc@gmai

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:344697
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to