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:
<cfscript> animals = ['cat','dog','fish','bison'] lastAnimal=animals.last() writeOutput("The last element of the array is: " & lastAnimal) </cfscript>
<cfscript> cfhttp(url="http://localhost:8500", timeout="60") </cfscript>
component{ 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:
<cfscript> param name="num" default="3" max="100"; writeOutput(num) </cfscript>
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.
It’s not “pointless”, when the very reason indicated for doing it above is to be more consistent with other languages, and when folks here and in other discussions on the web celebrate it. It may not be YOUR cup of tea (for them to have bothered), but do you really need to piss in the cup of others?
As for that edge case where the semi-colons are still needed, that’s not so much an “inherent weakness in the language”. That older param variant for cfparam in script is merely a way to do it that was added originally in the previous decade.
Since CF11 (from 2014), one CAN write about any tag as script, and one could pass the args in a way that does not require semicolons:
cfparam(name=”num”,default=”3″)
or
cfparam(name:”num”,default:”3″)
If you may feel that’s still not suitable to a “true OO language”, can you share how you would prefer to see it be written instead? Enlighten us, rather than denigrate.
Or if your beef is not so much with param/cfparam, or semicolons, but some other facet of CF that is lacking in OO sensibilities, share that or those. You may be surprised that many you would list have long-since been addressed, but if you’re really wanting to advance the conversation, here’s a good chance.
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.
You must be logged in to post a comment.