Writing CFMs without Semicolons

Semi-colons have been statement separators for most programming languages. Earlier when processing was slow and memory was expensive, language designers needed to split programs into multiple statements. A few languages required each statement to be on a new line so that the carriage return acted as a delimiter. Some languages required a free format text layout as a separator. Thus, the semi-colon was chosen as a separator so that it doesn’t conflict with other characters, for example, operators for math operations.

Many languages do not use semi-colons as statement separator, for example, JavaScript, Python, Golang etc. ColdFusion used semi-colons as separators from the first version. In the 2018 release of ColdFusion, we have made semi-colons optional.

There are some cases where it is mandatory to use semi-colons just to avoid ambiguity. CFML now  gives the flexibility to write code without semicolons in majority of the language constructs except a few, where it becomes necessary to avoid the ambiguity.

Some code snippets without semicolons as delimiter are shown below:

animals = ['cat','dog','fish','bison'] 
writeOutput("The last element of the array is: " & lastAnimal)
cfhttp(url="http://localhost:8500", timeout="60")

function myfunc(){
writeoutput("Optional Semi Colon Example")

There are some constructs where semi-colons have to be used to resolve ambiguity and proper functioning of code, for example:

param name="num" default="3" max="100";

In the above example if we don’t use semi-colons it creates an ambiguity whether we are trying to define the max value for a variable or  creating a variable with the name max. Hence semicolons will be required here.

2 Responses

  1. Your include example requiring semicolons makes no sense.

    include “blah.cfm” writeoutput(“test”)

    is totally clear as the speach marks indicate the file names.

    If you really wanted to include a file called “blah.cfm” writeoutput(“test” then you’d need to escape the marks, just link in any other string.

Leave a reply