Cfscript, Huh! Good God! What Is It Good For?

Posted: May 18th, 2009 | Author: | Filed under: ColdFusion | No Comments »

Why in the world would anyone want to take one line of code…

1
<cfset variables.Gouda = "" />

and turn it into three?

1
2
3
<cfscript>
	variables.Gouda = "";
</cfscript>

ColdFusion developers have been getting by just fine without using cfscript for quite some time. Some prefer old-school CF syntax to cfscript. It’s true that cfscript cannot do everything that ColdFusion can do*. There are some situations where avoiding cfscript is the best path.

There are several good reasons why you should incorporate more cfscript into your ColdFusion code. for one it’s easier to write. In the following two examples there are seven characters less per variable declaration in the cfscript version. The 35 character savings outweighs the 21 characters spent on opening and closing cfscript tags.

1
2
3
4
5
<cfset variables.American = "" />
<cfset variables.Bleu = "" />
<cfset variables.Cheddar = "" />
<cfset variables.Gouda = "" />
<cfset variables.Jarlesburg = "" />
1
2
3
4
5
6
7
<cfscript>
	variables.American = "";
	variables.Bleu = "";
	variables.Cheddar = "";
	variables.Gouda = "";
	variables.Jarlesburg = "";
</cfscript>

Personally I find the cfscript version easier to read. Another point to consider is the fact that cfscript syntax is similar to the syntax found in a host of other languages. My time spent working with cfscript syntax has paid off when it came time to sling some code in Flash ActionScript and JavaScript.

* Full language support for cfscript was just announced as a feature of ColdFusion 9.



Leave a Reply