A couple of developers and I have been discussing the practice of adding a closing slash to single line Cold Fusion tags. IE:
<cfset variables.sexyLady = "Olivia Munn"> <!--- Vs. ---> <cfset variables.sexyLady = "Olivia Munn" />
Some are of the camp that the closing slash is an extra key stroke and a waste of time. Others, like myself, feel that so long as there is no processing detriment attributed to the parser on behalf of the slash, it’s worth the extra keystroke for code readability. As a matter of fact, this exact reason is listed in the official Adobe Cold Fusion Development Standard:
Cold Fusion source code cannot quite be written to be purely XHTML-compliant because of certain tags (cfif / cfelse, cfreturn, cfset) but you should make an effort to be as XHTML-compliant as possible. cfelse cannot have a closing tag so it cannot be XHTML-compliant; cfif and cfreturn do not have an attribute=”value” syntax so they cannot be XHTML-compliant (but cfif has a closing /cfif tag and cfreturn can and should have a self-closing /); cfset does not in general follow the attribute=”value” syntax and these guidelines recommend that for readability you do not quote the value in cfset – but cfset can and should have a self-closing /. This makes the source code more consistent (across CFML and HTML) and will also help you avoid subtle errors such as unterminated nested cfmodule calls.
However; even though I am a proponent of the closing slash, I can’t help but wonder if readability is reason enough. When I take this a step father and look under the hood, it appears that Cold Fusion merely “strips out” the closing slash from inline tags during processing anyway. What this means is, that while there is no detriment to adding the slash, there is also no technological benefit to adding the slash. In this light, the perceived benefit becomes strictly an aesthetic advantage for the developer.
It appears that Adobe as standardized a preference.











June 2, 2010 at 5:02 pm
Another argument can be for consistency. If you code XHTML (and why would you not?!), all tags without a proper closing tag need the slash in order to maintain validation. If you do it for img, br, hr, met and link, why not in your CF code as well?
As a side note, I do it as well since I like XML syntax so naturally I like using this. I also agree with the aesthetic part, but for someone like me (and sadly there could be many!), not having the slash can be detrimental to coding period. When I go into someone’s JS or PHP code that is garbled and has no spacing consistency, I am less effective in debugging and thus my job has become more difficult.
June 3, 2010 at 7:21 pm
I am all for the consistency; for that reason alone I am a huge fan of the closing slash… but when I find out that there is no tech benefit to the trailing slash… that it’s strictly a cosmetic standard… I have a hard time with that. I usually like my standards to have better reasons that “it looks nice”. That being said, I still plan on using the closing slash.