Saturday, July 04, 2009    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Jan 2009 >>
S M T W T F S
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
             

Search

Categories
 • Acrobat (3) [RSS]
 • Adobe (76) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (66) [RSS]
 • AdobeMAX09 (10) [RSS]
 • AIR (190) [RSS]
 • Appearances (175) [RSS]
 • Books (70) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1278) [RSS]
 • Data Services (28) [RSS]
 • Fish Tank (3) [RSS]
 • Flash (144) [RSS]
 • Flex (458) [RSS]
 • Home Automation (3) [RSS]
 • Jobs (113) [RSS]
 • JRun (13) [RSS]
 • Labs (35) [RSS]
 • LiveCycle (30) [RSS]
 • MAX (205) [RSS]
 • Mobile (103) [RSS]
 • Regular Expressions (17) [RSS]
 • RIA (17) [RSS]
 • SQL (39) [RSS]
 • Stuff (524) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (154) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • Mark Doherty
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
January 13, 2009

CF9 Enhancement Slip

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? ;-)

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
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.
# Posted By charlie griefer | 1/13/09 2:36 PM
Good catch! ;-)

--- Ben
# Posted By Ben Forta | 1/13/09 2:37 PM
Is there an example of why allowing the var scoping of variables anywhere in the function be a benefit?
# Posted By Bryan F. Hogan | 1/13/09 3:03 PM
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).
# Posted By charlie griefer | 1/13/09 3:09 PM
is that struct notation as an argument to a function I see before me?
# Posted By marc esher | 1/13/09 7:02 PM
I don't see the "i" variable used in the loop being var scoped anywhere...
# Posted By John Whish | 1/14/09 3:37 AM
"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).
# Posted By Calvin | 1/14/09 5:33 AM
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.
# Posted By John Allen | 1/16/09 7:14 PM

  © Copyright 1997-2009 Ben Forta, All Rights Reserved