[thelist] Justification for Proper Scoping?

Joshua Olson joshua at alphashop.net
Sun Apr 22 06:08:07 CDT 2001


Frank,

The part of my response that you quoted was intended as a warning.  Let me
explain.

Suppose my one=page site contains the following form that submits back to
itself:

<form method="post" action="/index.cfm?myval=b">
  <input type="text" name="myval">
  <input type="submit" name="submit" value="submit">
</form>

<cfparam name="form.submit" default="">
<cfif form.submit IS "submit">
  <cfoutput>
    unscoped = #myval#<br>
    form-scope = #form.myval#<br>
    url-scope = #url.myval#
  </cfoutput>
</cfif>


If this was submitted, I was not sure if the output would be "b" because
myval is coming in from the URL, or "a" because that is what I typed into
the text field.

When I wrote:
"You will have to check for yourself the ColdFusion
precedence between the variable coming off the url and
form. I may have it backwards--though my point is the
same."

I meant that you should run the above test to make sure that the form
variable was overwritten by the URL variable, because I wasn't sure.  I've
tested it on a Win2K installation of ColdFusion and yes, the URL variable
does overwrite the form variable.

But as far as wasting time?  Yes, debugging headaches due to sloppy coding
is always equal to wasted time.  So, in that regard, it's not a bad
emphasis.  Remember, the whole idea of "good form" was based on the notion
that following best practices was common sense.  Seasoned professionals have
the pleasure of defining "good form" because they learned the hard way and
made these mistakes already.  So rather than repeat history and make the
same mistakes the experienced programmers have made, stand on the shoulders
of giants (Edison) and let yourself have an easy ride.  IOW, explain to your
coworker *who* outlined good form and what it was intending to combat, and
let him make an educated decision.

-joshua





More information about the thelist mailing list