While demoing the ORM features in Centaur (CF9) and Bolt (the CF IDE) during the MAX keynote, I showed and executed some code, and this snippet appeared on the screen for a short time:
<cffunction name="getAJAXGrid" access="remote" output="false" returntype="Any">
<cfargument name="page">
<cfargument name="pageSize">
<cfargument name="gridsortcolumn">
<cfargument name="gridsortdirection">
<cfif arguments.gridsortcolumn eq "">
<cfset arguments.gridsortcolumn = "DESTINATION_ID">
</cfif>
<cfset var Destination = EntityLoad("Destination", {}, "#arguments.gridsortcolumn# #arguments.gridsortdirection#")/>
<cfset var startRow = ((page-1)*pageSize)+1>
<cfset var endRow = page*pageSize>
<cfset var qry = querynew("destination_id,location,description")/>
<cfset QueryAddRow(qry,arraylen(Destination))/>
<cfif arraylen(Destination) lt endrow>
<cfset endrow = arraylen(Destination)/>
</cfif>
<cfloop from="#startrow#" to="#endrow#" index="i">
<cfset querysetcell(qry,'destination_id',Destination[i].getDestination_id(),i)/>
<cfset querysetcell(qry,'location',Destination[i].getLocation(),i)/>
<cfset querysetcell(qry,'description',Destination[i].getDescription(),i)/>
</cfloop>
<cfreturn QueryConvertForGrid(qry, page, pageSize)>
</cffunction>
I have now received three e-mails asking if that code was real or not. And the answer is yes, that is real code generated by Bolt, and it really was running in Centaur. Really! And yes, I know the code is not great (heck, it's not even that good, good thing we're not shipping yet).
But, you have to wonder, what made them ask? And did we inadvertently let a CF9 enhancement slip out of the bag? ;-)
<cfset var Destination = ... /> is preceded by a <cfif> block.
--- Ben
<cfif condition>
<cfset var myVar = "foo" />
<cfelse>
<cfset var myVar = "bar" />
</cfif>
...without having to explicitly set the <cfset var myVar = "" /> prior to the conditional (but you still could if you wanted to predefine the vars at the top of the function body).
I think the real question is, "is there a benefit to limiting declaration of function local variables to the beginning of the function?"
I would say that there isn't. Everywhere else that I 'declare' local variables I do so as close to the usage of the variable as possible, the current requirements for var break that proximity convention that can be used in: C#, JavaScript, ActionScript, Java and elsewhere in CF. (note: I am not thinking strictly of the keyword var in this observation, but local variable declaration).
<cfset var Destination = EntityLoad("Destination", {}, "#arguments.gridsortcolumn# #arguments.gridsortdirection#")/>
I'm way to excited about this.