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: 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? ;-)
CF9 Enhancement Slip
8 Comments
M
is that struct notation as an argument to a function I see before me?
C
i suppose if nothing else, it just offers for a bit more flexibility.
<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).
B
Bryan F. Hogan
Is there an example of why allowing the var scoping of variables anywhere in the function be a benefit?
B
Good catch! ;-)
--- Ben
C
looks like var declared variables no longer need to be grouped at the top of the function body.
<cfset var Destination = ... /> is preceded by a <cfif> block.
C
Calvin
"Is there an example of why allowing the var scoping of variables anywhere in the function be a benefit? "
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).
J
I don't see the "i" variable used in the loop being var scoped anywhere...
J
I am sooooooooooo excited I wont be able to sleep tonight. Ohhhhh Ohhh :
<cfset var Destination = EntityLoad("Destination", {}, "#arguments.gridsortcolumn# #arguments.gridsortdirection#")/>
I'm way to excited about this.