ColdFusion Scripting ColdFusion Help

Developers who are familiar with other scripting environments for Web application development, including JavaScript and Active Server Pages, often initially think that ColdFusion doesn’t offer full-scale scripting environment. This reaction comes from ColdFusion being tag-oriented whereas more traditional scripting environments are command, function, and expression based.

However, this focus on tags as the mechanism for all activity in ColdFusion belies the real power of the language. ColdFusion ‘contains almost every major programming construct expected by Web application devel.opers; they are just cloaked in the guise of tags.  Allaire, with version 4 of ColdFusion, is acknowledging that many developers are more comfortable with the style of programming used in JavaScript and other scripting environments. They have introduced a new Coldfusion scripting language that can be used to replace many of the tasks commonly performed with tags. In this chapter you will review scripting with the ColdFusion scripting language and learn how to use scripts in place of many common ColdFusion tags.

Scripting versus Tag-BasedCode

The goal of the ColdFusion scripting language is to make parts of ColdFusion functionality available in script-style syntax that developers may already be comfortable with.

This is not to say that everything done with ColdFtision’s tag-based syntax can be achieved through scriplS. Rather, any parts of ColdFusion that are truly programmatic (controlling flow, working with expressions, working with functions, and assigning variables) can be written in script syntax form. For instance, consider. the following program code:

CFIF Value is 1>
<CFSET Result· ‘One’)
<CFELSE> .
<CFSET Result ~ ‘None’)
</CFIF>

In ColdFusion script syntax, ‘the same code would be as follows:

<CFSCRtPT>
if (value is 1)
Result· ‘One’;
else
Result· ‘None’:
</CFSCRIPT>

Functionally these are the same. The choice of which approach to take depends on the preference of the developer.

The difference is even more pronounced when it comes to looping constructs. Although you can simulate all popular types of loops in programming languages such as ]avaScript and C by using the (FLClOP tag, the syntax of the tag itself does not make the purposes of the loop as readily apparent as they are in the scripting syntax.

For instance, the loop.

<CFlOOP INDEX-‘Value’ FROM-1 TO-S)

becomes

for (Value-1; Value less fhan 6; Value – Value + 1)

The latter is simply much clearer for an experienced developer coming from the world of traditional programming.

Posted on November 16, 2015 in ColdFusion Scripting

Share the Story

Back to Top
Share This