macromedia.coldfusion.getting_started
[Top] [All Lists]

Re: Why is this set? is it like cfparam for components?

Subject: Re: Why is this set? is it like cfparam for components?
From: Ian Skinner
Date: Tue, 03 Jun 2008 06:38:49 -0700
Newsgroups: macromedia.coldfusion.getting_started



It is more like a strongly typed language where one has to initialize ones variables before one can use them. In CF this initializes the variable so that it is local to the function, otherwise the variable will be global and if one does not account for the global nature, very hard to track bugs can be introduced into the code.

The best practice is to ALWAYS initialize local variable and to ALWAYS scope variables so that is is explicit when one is using local and one is using global 'variables' scoped variables.


<cffunction...>
...
<cfset var myLocalVar = ...><!--- initializes a local var --->
<cfset variables.myGlobalVar = ...> <!--- initializes a global var --->

<cfsomething myLocalVar ...><!--- uses the local var --->

<cfsomethingelse variables.myGlobalVar...><!--- uses the global var --->

<Prev in Thread] Current Thread [Next in Thread>