How can closures improve ColdFusion 9 ORM

It has been no secret that I have been trying to get closures into ColdFusion for over 18 months, I understand how the team has had its priorities already set in stone at the time, but lets have a look at how it can really help us developers.

Closures seem to be the talk of the town these days, with many people now blogging about them and how it could be really instrumental to the development of ColdFusion.

But I don't think people really understand how much code it actually will save us, especially when it comes to the CF-ORM side of the equation.

So lets look at how it can.

function searchByKeyword(keyword) {
criteria = ORMGetSession().createCriteria();
results = criteria.list {
   or {
    ilike("username", "${keyword}%");
    ilike("email", "${keyword}%");
    if (someCondition) {
      ilike("firstName", "${keyword}%");
    }
    ilike("lastName", "${keyword}%");
   }
}
return results;
}

I won't even bother to try to duplicate the above in ColdFusion 9 syntax, because it would result in much more code that is necessary. Since working on my dynamic find methods, I have so wished we had this in ColdFusion. Closures have to be the next major enhancement that comes into ColdFusion.



  • Ben Nadel's Gravatar Coming from Javascript, I would also love to have Closures in Javascript. However, I am concerned that they will never be possible in that Tag-based version.... which might cause big issues.

    If they were only in the Script-based, it might just be time for me to start using it ;)
    # Posted By Ben Nadel | 1/23/10 5:41 PM
  • Andrew Scott's Gravatar Ben, will have to agree with the tags. It would be hard to implement, but I am not sure it is impossible. Tags have a fairly nested code base to begin with, so it might be possible.

    However, personally I would rather see the script enhanced more with an OO approach, instead of creating hundreds more functions then we can use either the underlying Java or other methods introduced by ColdFusion. The tags could be just their to help with views, personal opinion I have with ColdFusion.
    # Posted By Andrew Scott | 1/24/10 3:00 AM