Skip to content

Instantly share code, notes, and snippets.

@sipacate
Created September 17, 2012 20:30
Show Gist options
  • Save sipacate/3739599 to your computer and use it in GitHub Desktop.
Save sipacate/3739599 to your computer and use it in GitHub Desktop.
Basics

##ColdFusion Tags vs. ColdFusion Script

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. There are one or two ColdFusion operations that 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">
<cfscript>
	variable = "value";
</cfscript>

Looping over an array:

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

<cfscript>
	FruitArray = ["apple", "banana", "cherry"];
	for( i=1; i <= arrayLen(FruitArray); i++){
		writeOutput(FruitArray[i]);
	}
</cfscript>

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment