Sep 23, 2009

Do you close your ColdFusion tags

Do you close your ColdFusion tags?

I do I like it, it looks cleaner and I know where code blocks end.  When I see code that is unclosed I can't help but "fix" it.

eg

or

Thoughts?

26 comments:

  1. I cant stand it! Its just another needless keystroke for me. So glad cfscript support is almost here so this will be a non-issue for me.

    The CF bundle for textmate adds the closing syntax and I always remove it. Sometimes I miss a few but I get most of them. yuck
    ReplyDelete
  2. I'm very much looking forward to script aswell ( in fact I have mentioned many times it's my most anticipated CF9 feature, but until then I'll be closing my tags :)
    ReplyDelete
  3. Paul I do the same thing, if I see it I will also close it as well.

    I guess its the XML in me, and agree that you know that the code blog ends there as well.
    ReplyDelete
  4. I close 'em. I close my HTML (xHTML) and I like to be consistent.

    If Russ and I ever worked together, we'd never get any work done. We'd be in an infinite loop of him removing closing slashes in my code and me adding 'em to his :)
    ReplyDelete
  5. I hate closing them..

    Search and replace '/>' with '>'.
    Search and replace 'access="public"' with ''
    Search and replace 'returntype="any"' with ''
    ReplyDelete
  6. I prefer to close them. Did notice that there is an issue with closing the cfmodule tag, causes it to execute twice i.e. <cfmodule />
    ReplyDelete
  7. IMO... just IMO...

    It's just a stupid thing to do. CFML is not XML, and makes no pretence of being XML. The only reason one would ever close a CFML tag unnecessarily is derived some drawing some parallel between XML and CFML which simply isn't there. Not all forms of mark-up are XML. The only people making a parallel between XML and CFML are the twonks that close their CFML tags and cite "[mutter] XML [mutter]" as a reason. Not a valid rationale.

    Anyone who makes a statement along the lines that they close their CFML tags because they like keeping them all nice alongside their XHTML tags (because, you know, they're kind of the same)... are even more misguided than the "let's play XML" bunch from above. CFML is nothing like HTML except for the angle brackets. Not a valid reason.

    The only good reason one might want to do this is conformity to the Adobe CFML standard - http://livedocs.adobe.com/wtg/public/coding_standards/printable.html - if one was to want to follow it blindly, verbatim, without giving any thought to why they were suggesting what they are doing ("as XHTML-compliant where (sic) possible"). I mean... adhering to a standard is good. But I wouldn't be adhering to a standard that has that nonsense in it.

    It's a practice borne of ignorance, serves no purpose, and simply adds more clutter to an already cluttered language.

    So... err... I'm a "no" to your question ;-)

    --
    Adam
    ReplyDelete
  8. I'm with Adam. It's unnecessary and a pointless extra keystroke. I'd say any compulsion to do it is similar to not treading on the cracks in between paving stones! (Obsessive Compulsive Disorder) You guys need to check in to a CFML doctor and get some cfpills. ;-)
    ReplyDelete
  9. I couldn't have said it better than Adam.

    I remove closing slashes with malice when I find them. They are the white whale to my Ahab.

    @Misterdai, re: cfmodule running twice when you close them.... that's the correct behavior. you'll get the same thing with a custom tag, too, since custom tags and cfmodule are damn near the same thing. It's because custom tags have the notion of a "start" and an "end". If your tag is a run-once tag, i.e. you don't need an opening and a closing, then you should put a block of code at the top that looks something like: if thistag.executionmode neq "start" {return};

    Otherwise, if you don't, some freak like charlie griefer will come along, use your tag, add an end slash, and be all "Why's this thing running twice?"
    ReplyDelete
  10. @Adam
    You are right of course. It's a waste of time and bytes. But then, how come I can't stop myself from doing it? There have been times when I had to make a 5 minute change to someone else's code, and I wasted another 5 adding those closing slashes everywhere. Oh, and I do the same thing with spaces and tabs.
    :o)
    ReplyDelete
  11. It's not that it's a waste of time or bytes, it's just that it's such a completely misguided enterprise to engage in.

    That said, an organisation should have a coding standard, and there should be a position documented on this practice (one way or the other), and all code should stick to it. If I land in a company that says I need to close my tags, I will do it. I will also take the issue up with whoever it is who maintains the coding standard and make them see the error in their ways, and get the standard fixed.

    However I think it's even more of a fool's errand to go around "fixing" existing code, one way or the other.

    --
    Adam
    ReplyDelete
  12. I think its funny how strongly people feel about something we all admit doesn't have purpose. I actually do close the tags even though I know it doesn't do any good...at this point its just habit that I think I picked up back in the day when I was forcing myself to write good XHTML. I don't do it because I think it does any good...but it doesn't do any bad either. Its funny since the argument against is about fewer keystrokes but people seem willing to go through the process of removing them - so is it about keystrokes? I suspect not.
    ReplyDelete
  13. I'm with Brian. I close them too. Just a preference. But I don't really feel THAT strongly about it (as strongly as those commenting here who DON'T close them and go through the trouble of removing them).
    ReplyDelete
  14. be careful with that. Some tags execute twice if you close them. Custom tags in particular. You can use the functions of the thistag structure to determine whether it's an open or close tag, or if it even has a closing tag.

    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=reuseCode_7.html
    ReplyDelete
  15. For tags that can ONLY be one tag, I think it doesn't matter (I do it out of habit.

    HOWEVER - for tags that have *optional* end tags, I think the self-close lends a visual key as to whether that end tag exists. This is especially true in custom tags.
    ReplyDelete
  16. For me, it's less about what I prefer for ColdFusion and more about establishing coding practices that allow me to move between languages without having to change the way I code. I tend to do the same thing with the quotes in ColdFusion. Most of the time the ColdFusion doesn't care if it's a single or double quote. However, some languages do. I just carry the habits over so I don't have to keep reminding myself to do it one way or another.
    ReplyDelete
  17. I prefer to close my CF tags, partly out of habit from writing good (read: valid) XHTML and partly because I think it looks good in the code (it's pleasing to my eye). Yep, that's a pretty ridiculous reason but it keeps me consistent when I write tag-based code or markup. For me, it's a case of no harm, no foul (so long as one isn't telling others that they 'have' to close tags and all that).
    ReplyDelete
  18. I close 'em. I don't feel that strongly. I do feel strongly about consistent and clean formatting, in general, whatever that format might be.

    Ben Nadel has made the one point I would have offered on this topic: "for tags that have *optional* end tags, I think the self-close lends a visual key as to whether that end tag exists."
    ReplyDelete
  19. Yes, I do. Consistency and the Adobe standard. Extra key stroke???? I can deal with an extra key stroke.
    ReplyDelete
  20. Anyone manipulate CFML with XSLT? ;)
    ReplyDelete
  21. I do I like it too Paul, I prefer Well Format Code with any programing Language.

    When I begin with Flex I felt so comfortable because I be doing well format code for years in other languages.
    ReplyDelete
  22. to close our tags or to not close our tags http://tinyurl.com/ya92og2
    ReplyDelete
  23. I'm the bane of several of my coworkers who slavishly close their tags. When they compare files that I've edited in Subclipse they find lots of changes because I remove their silly little closing tags with a vengeance.
    ReplyDelete
  24. I always close my tags in CFML if they don't have a closing tag. Purely for my own preference though.

    I did notice that the cfpod tag requires the closing slash if the closing tag is not used in the CF8 documentation. However, I've never had a need to use cfpod.
    ReplyDelete
  25. I know this is an old post, and i dont like to open up raw wounds (who does? apart from an old gf I once had but thats a different story...) The reason I began looking for this is that there does NOT seem to be a standard AT ALL...

    I have just begun learning CF from using PHP and .NET for a few years and I like to close my tags (or at least use the 'self closing' - how every you would like to state it) the reason for me is NOT because it gets on my nerves because they are/are not there, its for simplicity.

    When I began using PHP it would drive me nuts when I came across 'if', 'while' and other loops where people did not use curly braces, that drove me mad because although you can use 'endif' or 'do' etc etc etc it is not actually required, this would lead me to read code that appeared to be incomplete, now I come across a similar situation within CF, adn though this does not annoy me anywhere near as much as the curly braces within PHP does, I still close tags for neatness, when you see a closed tag you know that it is a single line of code and you are not waiting for the closing tag later on down the page.

    My final twopence is for a early comment made about 'spaces and tabs' - I used to do this too, until I realised that some IDE's make no distinction between the two at all, that is, it treats them all as white space. In Dreamweaver you could tab al your code nicley and it will look fine, open it again and the tabs are there. But if you open the same file in PSPad then all tabs are automatically converted to spaces, I did not notice this until i realised that I had gone over the same file three times replacing spaces with tabs, then at work I would open up in PSpad and find that the had all been converted again.

    The long and shor of it is this IMHO, all programmers need a little bit of OCD in order to function and to actually trawl through 3 million lines of code in order to make them look 'neat' and 'tidy' for the few people who will actually be looking at the code!

    Lets face it, unless you are expecting to create an application that will be used by millions of people then your code just needs to work because it will probably be only viewed by you, your line manager and your clients
    ReplyDelete