Long email :O)

To answer one point, if you want to set an APPLICATION var only if it
doesn't exist, do it in the Application.cfm file. Wrap it in an if statement
...

<cfif NOT IsDefined("APPLICATION.myVar")>
        <cfset APPLICATION.whatever = "hellacool">
</cfif>

Ade

-----Original Message-----
From: Jay Packer [mailto:[EMAIL PROTECTED]]
Sent: 25 September 2002 22:40
To: CF-Talk
Subject: Best coding techniques for use of Application variables


Hi,

I have some questions regarding the use of application variables that I
was hoping for some suggestions on.

First is the issue of locking. If I understand correctly, I'll gain a
small performance boost if I do my own locking instead of allowing CF to
automatically lock all READS via the CF administrator. Secondly, when
doing my own locking, what the best way to use variables on the page?
Instead of putting locks around chunks of code where application (or
session) variables would be used, I've been reading my variables into
the local scope at the top of my templates where they're needed, like
this:

<cflock>
        <cfset variables.x = application.x>
</cflock>

By reading the variables into the local scope, I can use any app/session
variables without having to worry about where I'm placing my locks later
on down in my code. I just wondered if this was a good/appropriate
coding technique or if I should be doing something else.

Also, what's the best way to initialize application variables? If I've
got a list of application variables, some coming from database values,
it seems inefficient to run a query and set the variables on the
Application.cfm page because every time a user requests a page, this
code will get run again. It seems far better to detect if my application
variables have already been initialized and if not, then use cfinclude
to call a template where the query gets run and the variables get set. I
could do this by having a variable called application.isInitialized. It
gets set at the end of the page where all my application variables are
set, and if it is defined, then I don't need to re-initialize my
application variables.

Here's a really important question: In the above case, will all the
other application variables exist if application.isInitialized is
defined? (I'm setting them all at the same time on the same template).

To word the question another way, how can I be sure that all my
application variables exist so that I don't have to "re-set" them every
time Application.cfm runs.

A college student, I've been coding in CF for about four years now.
Although I think the language is powerful, flexible, and intuitive, at
times I find its documentation and/or examples to be serverly lacking.
Time and time again, I've seen example code from Allaire (formerly) and
now Macromedia that uses application/session variables without locking
them at all. You would think that issues I've just asked about would
have been clearly explained in the documentation, but they're not. When
people have instability with CF, the number one culprit is improper
locking. I think the reason that this is so is due to a lack of good
examples on how to use the cflock tag. Sorry to rant as I'm no doubt
preaching to the choir.

Thanks in advance for any help!

===========================
Jay Packer
[EMAIL PROTECTED]
===========================


FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to