July 3, 2008

Pages


Search Site


Topics


Useful Links

Blogs I Read


Archives

The Most Important Enhancement in ColdFusion 8

May 31 2007 by Andrew Powell
ColdFusion 8 has a TON of new features, and they're all great. Some will help productivity and some will help with the GUI. However, there are a number of CFML enhancements that nobody has really talked about. For me, one stands head and shoulders above them all. It is the single most important enhancement to CFML since the introduction of CFCs. What is it? duplicate() now works on CFCs. Let's stop and say that one more time, for effect. duplicate() now works on CFCs. What does this mean? It means, in geek speak, that we can clone or create a deep copy of a CFC. Until now, you could only pass CFCs around by reference (a pointer to the memory space occupied by the object) instead of by value. This will allow ColdFusion developers to do things like keep value objects in the application scope and take copies of them, when needed, for singletons. Now, instead of going to createObject() each time we need a new object, we simply read the object out memory as a copy. A sample init function within a cfc (we'll call this one foo.cfc and assume it's in the root, for the sake of brevity) might look like this: <cffunction name="init" access="public" output="false" returntype="foo">
<cfargument name="argumentA" type="string" required="true"/>
<cfargument name="argumentB" type="numeric" required="true"/>
<cfscript>
var returnObject = duplicate(this);
returnObject.setPropertyA(arguments.argumentA);
returnObject.setPropertyB(arguments.argumentB);
return returnObject;
</cfscript>
</cffunction>
This enhancement could have a lot of impact on the various frameworks out there (Peter, Matt, & Kurt are you paying attention?). There's a lot of createObject() going on in Mach-II, ColdSpring, Model-Glue, etc. This has the potential to help speed up your favourite framework, so applications you already have can benefit from this new feature once the frameworks are updated to use it. To me, this is, easily, the most important new feature of ColdFusion 8. Well, this and CFTHREAD (no flame wars please Vince & Damon), but that's another post.

Posted in ColdFusion | General | ColdSpring | Adobe | Mach-II | 6 comments

6 responses to “The Most Important Enhancement in ColdFusion 8”

  1. Peter J. Farrell Says:
    <p>Sadly, using duplicate() in this manner in Mach-II cuts out 7 and 6.1 users. Andy, is duplicating an object going to be any faster that CreateObject()? Behind the scenes I can only assume basically that is what's going on. I smell a follow up post -- duplicating 10 copies of the same obj and creating 10 and timing them for performance.</p>
  2. Sean Corfield Says:
    <p>I am concerned that a lot of people are going to get very, very badly burned by this new feature.</p>

    <p>If you have transient objects that contain a reference back to a singleton and you duplicate() them, you will get a full duplicate of your singleton as well. That's very dangerous, especially around frameworks.</p>

    <p>Most frameworks use this model, placing a reference to singleton framework core objects into any transients they create.</p>

    <p>Also, given the incredible performance improvements in createObject(), I'm not sure this duplication of prototype objects is even worth considering.</p>
  3. Sean Corfield Says:
    <p>OK, so a simple benchmark test shows that createObject() is *much* FASTER than duplicate()...</p>

    <p>1000 creates of a simple object takes just under 50ms.</p>

    <p>1000 duplicates of that same simple object takes 3-4 seconds!</p>

    <p>1000 create + init calls takes around 60ms.</p>

    <p>1000 duplicate + init calls takes, you've guessed it, 3-4 seconds.</p>

    <p>So, no, duplicate() will not speed code up.</p>
  4. Andrew Powell Says:
    <p>I'm thinking this is a good thing because it will allow for cleaner code and easier management of object creation. </p>

    <p>I didn't say it would be faster, I just said it will allow for easier management of objects.</p>

    <p>Ironically enough, the captcha for this comment is "bs".</p>
  5. Adam Says:
    <p>As a longtime CF developer, I say it's about time Adobe calls the language a mistake, apologizes, and buries it. I like it for the simplest project, but when that project grows, it turns into a hacked-up mess. Global variables, no type safety, disjunct syntax (tags and cfscript), a rotten debugger, bastardized OO structure, ... Enough.</p>
  6. Sean Corfield Says:
    <p>@Adam, assuming you're not a troll, I'll respond:</p>

    <p>A rotten debugger? Have you actually used the debugger in Eclipse with ColdFusion 8? What's "rotten" about it?</p>

    <p>As for type safety, it's a *dynamic* scripting language! Heard of Ruby? Smalltalk? They work the same way.</p>

    <p>For large projects, it only "turns into a hacked-up mess" if you're writing poor code - and a bad developer can write poor code in any language (I used to be in the software analysis business - I've reviewed millions of lines of code in several programming languages so I can say that with some authority! :)</p>

    <p>Global variables? Lots of languages have global variables. Again, it's poor programmers that create a mess with global variables. It's worth pointing out that Java gets itself in a knot implementing the Singleton design pattern precisely because it does not have global variables and has to work around it.</p>

    <p>I won't argue the syntax point other than to point out lots of languages have some serious syntactic fugliness (and I'm speaking as a compiler developer and long-time member of the ANSI C++ Standards Committee :)</p>

Leave a Reply