Script vs Tag

By Dan Wilson (Bio)

ColdFusion has been designed to allow the use of ColdFusion tags and ColdFusion script. Functionally, both will be interpreted equally and will achieve the same result. The use of ColdFusion Tags and ColdFusion Script is up to personal or team preference. One or two ColdFusion operations are currently Tag only, as of this tutorial, but these will be made available in ColdFusion script in future releases.

Some developers write all ColdFusion code in Tags. Some developers write all ColdFusion code in Script. Some write the view portions of their ColdFusion code in Tags and the business layer portion in Script. As long as you stay consistent, all approaches are valid. The overarching rule should be legibility and consistency.

Let's look at some statements and compare the differences:

Setting a Variable:

<cfset variable = "value" />
    variable = "value";

Looping Over an Array:

<cfset FruitArray = ["apple", "banana", "cherry"] />
<cfloop from="1" to="#arrayLen( FruitArray)#" index="i">

    FruitArray = ["apple", "banana", "cherry"];
    for( i=1; i <= arrayLen(FruitArray); i++){

Some developers find the ColdFusion Script syntax to resemble other familiar programming languages. ColdFusion is designed to provide a welcoming and productive developer experience. Try both styles to see which you prefer. The ColdFusion documentation has several good pages on ColdFusion script. http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7feb.html