Chris Peters: Web Developer

I still agree with Ben Forta about when to use custom tags versus CFCs

Filed under: Programming — Chris Peters, March 20, 2006

I read Ben Forta’s opinion on when to use ColdFusion components (CFCs) versus custom tags over two years ago. After much practice, I still agree. Custom tags are great for presentation abstraction and data formatting, and CFCs are great for abstracting processes, business logic, etc.

“Usability” of your code

I remember when I first started my current job, a colleague of mine used the word “usability” in reference to reading and writing each other’s code. I thought the usage of that word was awkward, but it somehow made sense. Writing your code in a way that makes it easier for others to read and maintain does in a sense make the code more “usaable” for other developers.

In terms of displaying or formatting content, custom tags make a whole lot more sense. Think about the type of person who is concerned with a page’s appearance. They more than likely know HTML, which is tag-based. They less likely know about object oriented programming, or even procedural programming itself. They more than likely would understand this custom tag call:



better than this comparable CFC call:






#stateList.display()#

In contrast, a CFC has abilities that makes a developer with an OOP background salivate. They now have the ability to use terms like inheritance, introspection, encapsulation, and instantiation amongst their colleagues who sport Computer Science degrees. And there is definitely a place for that.

What went wrong?

Neither usage of the “state list” example above are necessarily wrong. I know that there are many ColdFusion developers out there who will only write their own code, with no risk of others ever needing to use it in any way. And that’s OK.

And when you get a book about ColdFusion MX and learn about the <cfcomponent> construct, you want to use that feature in as many ways as possible for bragging rights.

When you’re in a team environment like mine, you can’t afford the time to keep re-explaining how to use an object to your designer. The designer just doesn’t think well in those terms. And that’s OK.

So here’s another lesson in forward thinking. If you intend on others ever using your code and finding value in it (of course, we don’t like to do anything that doesn’t contain value), think about the implications behind which construct you use. If you were hit by a bus tomorrow, would the next guy (or gal) understand your code? Do you want people cursing your existence when they have to use your code after you’re gone? I didn’t think so!

Technorati Tags:
, ,

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment