[thelist] CF: Determining which DB used.

.jeff jeff at members.evolt.org
Wed Sep 12 12:57:59 CDT 2001


raymond,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Raymond Camden
>
> Again, I'm just telling ya what I know. :)
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

any chance of getting some feedback from someone that does know?  *grin*

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> Correct. This is expect since "Server" is not a valid
> Struct. However, I don't consider this yucky per se,
> if I were storing stuff in Server I'd just do:
>
> <CFIF NOT IsDefined("Server.Foo")>
> 	... start setting crap up ...
> </CFIF>
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

i just find any use of the IsDefined() function icky.  i've too often found
it to be used to combine strings and variables to check if something is
created making the process of debugging and maintenance a royal as it's
often quite hard to determine what value the variable portion might contain.

even without this use of the IsDefined() function, the best practice i
adhere to is one that maintains that any variable you're going to be
accessing should already be created.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> which is the same kind of code you use before setting
> application variables. (And if you DONT do this, you
> should!)
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

actually, there's a *far* better way to do it with application scoped
variables as the application scope is a structure.  following the best
practice mentioned above, the variable should already be defined anyway,
which would dictate something like this (which you'll see commonly in code i
write that uses application variables):

<cflock
 scope="application"
 type="exclusive"
 timeout="10"
 throwontimeout="no">

  <cfif NOT StructKeyExists(application, "categories")>
    <cfset application.categories = StructNew()>
    <!--- the rest of your setting happens here --->
  </cfif>

</cflock>

alternatively, even with the server scope, you could use the following
approach where you initialize the variable as a simple value, then check
whether or not it's a complex value of some type, and if not "enhance" it.

<cflock
 scope="application"
 type="exclusive"
 timeout="10"
 throwontimeout="no">

  <cfparam name="application.categories" default="">

  <cfif NOT IsStruct(application.categories)>
    <cfset application.categories = StructNew()>
    <!--- the rest of your setting happens here --->
  </cfif>

</cflock>

(fwiw, i see that my co-worker joshua has posted the same approach)

thanks,

.jeff
("dogmatic" project manager)

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list