I was pretty slack about scoping variables when I first
started working with ColdFusion and for a while I tried to
leave form and url variables unscoped intentionally,
although I've given up that habbit. I like to copy all my
form and url variables into an attributes structure in the
application.cfm which allows me to use base templates as
custom tags if the need arises and it's only 3 short, sweet
lines of code. (It's one of the nicer tricks from Fusebox)
If you use New Atlanta's BlueDragon server it's only 2 lines
of code because BlueDragon automatically combines the form
and url variables, so referencing form[var] is the same as
referencing url[var].

I've mostly gotten out of the habbit of unscoped variables,
and try even with the variables scope to scope them because
sometimes when you don't scope them during a set statement
they don't actually get into the variables scope, although I
don't know how or why they don't. If I need a temp variable
quickly for a loop or the like, I'll frequently use a single
character variable like x or i unscoped, only if I know that
I've set it and am making all references to it in the same
template. And of course, if it's in a function or a CFC
method, I always make sure to use <var> to declare the same
single-character variables just in case.

Is scoping one of the first things a cf developer should
learn? Maybe. I think so. I know the question of scoping has
sparked minor flame wars on the cf-talk list. Not by any
means like the flame wars sparked by the issue of locking,
but they've happened.


s. isaac dealey                972-490-6624

team macromedia volunteer
http://www.macromedia.com/go/team

chief architect, tapestry cms  http://products.turnkey.to

onTap is open source           http://www.turnkey.to/ontap


> Thought I would spark up a quick discussion.

> I was discussing a few things with a coder (no names), and
> I raised the
> subject of scoping variables.

> I am a real stickler when it comes to scoping variables.
> Other than obvious
> performance gain, and not having the issue of values
> bleeding from one scope
> into another - scoping simply makes code much easier to
> read.

> Looking at the variable #customer# tells you there is a
> variable named
> customer.  Looking at the variable #form.customer# or
> #qInvoice.customer#
> tells you where the value came from and some insight on
> how it is going to
> be used, why, etc...  (Especially when you deal with more
> than one page per
> request)

> I do on the other hand leave local scoped variables alone
> (the
> variables.[name] scope) - Which I think is standard
> practice, and there is
> no ambiguity when only one scope follows such a
> convention.

> I was curious if anyone else had a differing view of
> scoping.  Perhaps
> (though I highly doubt) someone can give me an example of
> when leaving off
> the scope of a variable name has an actual advantage.

> The only idea that was half valid was using either
> form/url scope.  This of
> course can be solved by coping one scope into the other
> and can be done in a
> few lines, so in the end, I don't think it's much of a
> valid point at all.

> Am I alone in thinking scoping variables is an absolute
> must, and pretty
> much day one stuff?

> Best Regards,

> Nate Nielsen
> [EMAIL PROTECTED]

> -----------------------------------------------
> To post, send email to [EMAIL PROTECTED]
> To unsubscribe:
>    Send UNSUBSCRIBE to [EMAIL PROTECTED]
> To subscribe / unsubscribe: http://www.dfwcfug.org





-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To unsubscribe: 
   Send UNSUBSCRIBE to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org

Reply via email to