I agree that not scoping is generally a bad idea. I like to scope,
unless I'm looking for url/form ambiguity - but if I am, then it should
be documented. Also, I tend to not scope "private" (per my
architecture; regular CFML doesn't maintain the concept of private
outside of functions/custom tags), but I like to use the practice of
prepending private vars with an underscore:
<cfset _somePrivateVariable = someValue>
For the most part, I know if my code has an unscope variable without a
prepended underscore, then it's implied as form or url scope.
Though it might be a good idea to utilize a custom scope for ambiguity,
something like this in the Application.cfm:
<cfset request.urlForm = structNew()>
<cfloop collection="#form#" item="i">
<cfset request.urlForm[i] = form[i]>
</cfloop>
<cfloop collection="#url#" item="i">
<cfset request.urlForm[i] = url[i]>
</cfloop>
Disclaimer: any best practices I advise are not necessarily in code I
have written in the wild, since I'm lazy. :-)
---
Billy Cravens
Web and Software Consulting
www.Architechx.com
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On
Behalf Of Ferguson, Ken
Sent: Thursday, June 20, 2002 11:52 AM
To: '[EMAIL PROTECTED]'
Subject: RE: CFMX - Did you know...
My point is concerned not with the importance of scoping in and of
itself as
much as it is with reusability and ease of maintenance. How many times
have
you taken over someone else's work only to find that there are variables
all
over the place which are neither scoped nor commented upon? The question
is
not whether or not you have the ability to make coding decisions for
yourself, but whether you're developing applications responsibly and
with an
eye towards the future when you may not be available to assist in its
maintenance. If you find a valid reason for having a variable which is
not
scoped, comment it to ensure others can understand your reasoning.
Ferg
-----Original Message-----
From: Jacob Cameron [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 20, 2002 11:37 AM
To: [EMAIL PROTECTED]
Subject: RE: CFMX - Did you know...
Disagreed,
It has nothing to do with should. When I interchange form. and
URL.
or
request.form or request.querystring I do it on purpose and for a reason.
It's not that I don't know how to qualify, for some 'strange' reason
some
applications make it necessary. I think that every variable should be
scoped, unless there is a good reason not to, and I can think of a few.
Taking away the ability for the developer to decide when to use this
option
and when not to is not a good idea if you ask me. Anyone who has been
doing
scripting for a while knows that there is an order for the search, same
as
there is an order for the search when looking for custom tags:
<CF_mynewtag>.
Do all of you qualify your tables with owner.tablename? Do you
also
do
DBName.owner.tablename? How about instance.DBName.owner.tablename, this
way
you can setup one connection to your DB server and call all queries out
of
the correct area based upon your scoping. (Dependant on your RDBMS).
Think through it, why is it so bad? Are you not capable of
making
coding
decisions for yourself? Is that why you do CF because you are limited
so
much? You need other programmers who are probably no smarter than you
decide what you can and cannot do?
I've been doing CGI since before CF and ASP, and have done
thousands, yes
thousands, of website. Some with lots of hits, some with lots of data,
some
with lots of diverse systems integrated. I do not believe taking out
this
coding option is a good idea.
That is just my thoughts.
Jacob
PS. Just read Dan's, I'm glad this option is not gone:)
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Jeremy Ridout
Sent: Thursday, June 20, 2002 11:19 AM
To: '[EMAIL PROTECTED]'
Subject: RE: CFMX - Did you know...
Agreed, Matthew.
Im looking through the documentation for the exact text to back up my
statement. I originally got the information from a presentation at the
CFUN02 conference this last weekend.
Jeremy
-----Original Message-----
From: Matthew Morvant [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 20, 2002 11:11 AM
To: '[EMAIL PROTECTED]'
Subject: RE: CFMX - Did you know...
Shouldn't we all WANT to scope our variables, regardless of what is
allowed
or not allowed. Why would we want to use an upgraded product without
upgrading our code to go with it. I am as lazy as the next person when
it
comes to not explicitly scoping locals, but all the other scopes should
be
explicitly defined no matter what the server will let us do.
Just my .02
Matthew
-----Original Message-----
From: Billy Cravens [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 20, 2002 10:57 AM
To: [EMAIL PROTECTED]
Subject: RE: CFMX - Did you know...
I don't think this is true - there's still an implied scooping hierarchy
(quoting from MX documentation):
If you use a variable name without a scope prefix, ColdFusion checks the
scopes in the following order to find the variable:
Arguments
Variables (local scope)
CGI
URL
Form
Cookie
Client
---
Billy Cravens
Web and Software Consulting
www.Architechx.com
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On
Behalf
Of Jeff Mayfield
Sent: Thursday, June 20, 2002 2:52 AM
To: [EMAIL PROTECTED]
Subject: Re: CFMX - Did you know...
At 6/19/2002 04:15 PM, you wrote:
>3) Scoping of all variables is REQUIRED in CFMX. Only the variables
scope
>does not require an explicit named scope.
>
>For example, #CFID# will NOT find #Client.CFID#. You can also no longer
>leave off the scope for form or URL variables and expect CF to locate
the
>variable. It will search the variables scope and then throw an error if
the
>variable name doesnt exist in the variables scope. You now must write
>#form.thisvar# and #url.thatvar#
Are you sure there's not an administrative setting that can override
this
behavior? Based on how I write code, and what I've seen in every single
project I've inherited from other companies - there's going to be a lot
of
broken apps.
How does Macromedia claim backward compatibility?
------------------------------------------------------------------------
-
This email server is running an evaluation copy of the MailShield anti-
spam
software. Please contact your email administrator if you have any
questions
about this message. MailShield product info: www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org
------------------------------------------------------------------------
-
This email server is running an evaluation copy of the MailShield anti-
spam
software. Please contact your email administrator if you have any
questions
about this message. MailShield product info: www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org
------------------------------------------------------------------------
-
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info:
www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org
------------------------------------------------------------------------
-
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info:
www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org
------------------------------------------------------------------------
-
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info:
www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org
------------------------------------------------------------------------
-
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info:
www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org
-------------------------------------------------------------------------
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info: www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org