Custom Tags Versus CFCs

It is possible to write an entire ColdFusion application using just Custom Tags (and a single file as an entry point). Similarly, it is possible to write an entire ColdFusion application using just .cfc files (I’ve yet to see one of these, but it is doable). So, when should Custom Tags be used? And when should .cfc files be used? Where is the logical spilt between them?
While in London last week, I got into an interesting discussion on just this subject with Simon Horwith (initially at a customer site, and continued the next day at a local Starbucks). The truth is that there is a lot of overlap in the capabilities of Custom Tags and ColdFusion Components, and I don’t believe there is an absolute right or wrong here, but, here’s what we agreed on …
CFCs are best-suited for data abstraction, for business logic and transaction encapsulation, for processes, for doing stuff. While CFCs can indeed be used to generate and even display output, that is not their core strength. CFCs provide basic object type functionality (not true objects, I know, I am not going to get into that discussion here), and are best used where objects would typically be created and used. That is not to say that CFC methods should never render output, they may (although I’d want specific methods, or inherited CFCs to be used for this). But that is not where they add real value to ColdFusion development.
Custom Tags, however, are perfect for presentation and data formatting. In fact, that is what they are best at (they are only used for everything else because CFCs were first introduced in CFMX, we used Custom Tags because we had no better option). The syntax, the use of tag pairs and child tags, multiple execution modes, the simplified attribute passing, all of those make Custom Tags perfect for wrapping around content so as to present it as needed. And the lack of multiple entry points, the lack of formalized parameter passing, the lack of persistence and inheritance, all of those make Custom Tags poor choices for data and logic abstraction.
So, CFCs for logic and data abstraction, Custom Tags for presentation, and good old .cfm files to hold it all together. Considering capabilities, usability, and performance, that seems like the best combination to us. If you have another opinion I’d love to hear it.

7 responses to “Custom Tags Versus CFCs”

  1. Tony Blake Avatar
    Tony Blake

    Are you a fan of something like Mach-II or Fusebox 4 holding it together, because these frameworks tend to make custom tags a little redundant (via the use of content variables)?
    Or are you a fan of using "good old .cfm files" by themselves?

  2. Brian Avatar

    I’ve mentioned this before to Macromedia. Imagine being able to associate a CFC to a page, thus custom tag, like user controls/code behind in It could combine the advantages of both constructs.

  3. seancorfield Avatar

    Tony, I don’t see that Mach II makes custom tags redundant. We’re building Mach II applications and still find custom tags to be very valuable in the views to help with formatting data etc. In fact if you read my team’s ColdFusion MX Coding Standards and the Mach II Development Guide, you’ll even see specific examples of custom tag usage:

  4. Micha Schopman Avatar
    Micha Schopman

    Performance with custom tags is great. A CMS app I wrote uses a single core, based on a custom tag framework model, and this single core is shared upon 20+ websites.
    I get execution times of 16ms for an entire page, uncached.

  5. Christian Cantrell Avatar
    Christian Cantrell

    I completely agree with Ben’s and Simon’s assessment. An even more interesting topic, however, might be CFCs vs. UDFs.

  6. John Farrar Avatar
    John Farrar

    This blog post inspired some refactoring of code that started long ago. It turned into a project called COOP.
    Tony… content variables aren’t as powerful as custom tags. CFCs at any time of the day can’t do a number of things that custom tags can do.
    Brian… some developers have commented that the type of code you describe is achieved by COOP.
    What we need is a framework that works with Fusebox and other Frameworks. COOP takes two of the power hitters and puts them on the same team. Traditionally we compared CFCs to Custom Tags in the community rather than learning the best way to use both of them. I am among those who basically stopped writing custom tags for a season. Yet my love of CF and creativity drove me to look at taking the concepts of what makes ColdFusion a hall of fame development language and drove me to take it to a new level along the same theme. We are planning to release RC1 of COOP to the public next week.

  7. sosensible Avatar

    So long since I read this post. Just wanted to comment, looks like Angular, React and Vue echo the sentiments here but in the other direct. Custom tags came later!

Leave a Reply