Full CFScript CFCs Aren’t Yet Where They Need To Be

April 17, 2010 · Chris Peters

A few months ago, I blogged about my excitement about the role that full script CFCs could have in an MVC stack, particularly with CFWheels. Unfortunately, the CFScript part of ColdFusion isn't quite where it needs to be yet.

A few months ago, I blogged about my excitement about the role that full script CFCs could have in an MVC stack, particularly with CFWheels. In my excitement to try out the new feature, I had spent much of a Saturday manually converting all of my components into CFScript components in a project that I am working on.

Unfortunately, the CFScript part of ColdFusion isn’t quite where it needs to be yet.

Don’t get me wrong: CFScript is much improved over where it was in previous versions of ColdFusion. And I don’t get angry when I experiment with a feature and it doesn’t work out, but I also try my hardest to know when to back off and undo any damage before it goes too far.

What didn’t work

As it turns out, doing custom database queries in CFScript is very cumbersome. It starts feeling a little too much like PHP. Maybe even worse!

Consider this beautiful, expressive simplicity that we all love about CFML:

<cfquery datasource="#get('dataSourceName')#" name="local.apps">
SELECT DISTINCT
A.*
FROM
apps A
JOIN appgroupmemberships G
ON A.id = G.appid
WHERE
G.usergroupid IN (#local.groupIds#)
AND deletedat IS NULL
</cfquery>
view raw query-tag.cfm hosted with ❤ by GitHub

And replace it with this garbage:

local.queryService = new Query(datasource=get('dataSourceName'));
local.queryService.setSql("
SELECT DISTINCT
A.*
FROM
apps A
JOIN appgroupmemberships G
ON A.id = G.appid
WHERE
G.usergroupid IN (#local.groupIds#)
AND deletedat IS NULL
");
local.apps = local.queryService.Execute().GetResult();

The last line is the part that really gets me. What is this, Java?

Also, it gets much worse when you need to cut in and out of the SQL string that you’re building in order to add in if logic, loops, calls to AddParam(), etc.

The other big annoyance to me is CFScript’s lack of coverage for many of the other data communication tags. It hurts to not have equal functionality available for cffeed, cfldap, etc. I need to call more than just databases in my models and controllers.

Realization: I need to support Railo too

I need to work on adding support for Railo, which doesn’t yet support full script-based components anyway. So it was probably in my best interest to take some time to convert my components back to CFML again.

Perhaps our paths shall cross again some day, CFScript. Until then, I bid you adieu.

About Chris Peters

With over 20 years of experience, I help plan, execute, and optimize digital experiences.

Leave a comment