> Isn't it a bit illogical to use request scope for storing 
> constants if they can be overwritten? 

Since CF doesn't provide anything directly analogous to a constant, it's as
close as you can get. Typically, when used as "constants", request variables
are created in Application.cfm for each page request. They'll have the same
values for each page, since the value will be hard-coded in Application.cfm.
Conceivably, the value could be changed lower in the page, but in all
likelihood, it wouldn't be. For example, if you wanted to reference the
datasource name as a variable, it's going to have the same through the
lifetime of the application - the value isn't going to change as a result of
some action within the application.

On the other hand, if you wanted to have variables which did change over
time, that's a good use of the Application scope. For example, if you wanted
to track how many users were in an application, you might set a variable in
the Application scope, and change it as users entered and left the
application. In this case, you wouldn't be using the variable as a constant
at all.

> I understand that there is no sense in doing <cfif
> isdefined("request.myvar")....> as the variable will be 
> destroyed no matter what, so you have to always re-initialize 
> it. Does that carry more or less penalty than checking for 
> existence of an application scope variable with isdefined()?

Again, if the variable is set in Application.cfm in the Request scope, this
won't be an issue - it will always be there! As for whether there's less
overhead in setting a variable in the Request scope on each page request
than setting it once in the Application scope then retrieving that variable
on each page, I honestly don't know. The overhead in either case is likely
to be so low as to be nearly immeasurable, and I'd let ease of use and
readability carry the day - which in my mind would favor the use of the
Request scope for these "constants".

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to