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.
Leave a Reply