Interview for Working with Custom Tags
"Working with Custom Tags" interview with Raymond Camden
***********************************************************
Michael Smith: This time we are talking with Raymond Camden about his CFUNITED-
05 talk "Working with Custom Tags". So why should a developer come to your
session Raymond?
Raymond Camden: If you are a beginner in the world of ColdFusion, you have
already discovered how easy CFML is to work with. After mastering the basic
syntax, one of main ways you can help improve your code is to work on
reusability. Custom tags are one of the many ways you can package and reuse code
in ColdFusion. This session is targetted to the BEGINNER developer who has not
yet worked with custom tags.
MS: Why does reusability improve code?
RC: Reusability simply means to reuse what you have done before. It saves time:
This is a bit obvious, but if you spend a week building an interface to an
ecommerce system and can use it again - you have just saved a week of time. It
also makes your code stronger. If that ecommerce code has a bug in it and 10
applications use it - you can fix it for all 10 applications by simply fixing it
in one place.
MS: That is cool! But doesn't it take a lot longer to write the code to be
reuseable in the first place?
RC: I wouldn't say a lot longer. It certainly does take more time to write
encapsulated code, however that time is more than made up later on when you can
reuse the code you wrote. I also find that the extra time allows me to take a
closer look at what I'm doing. Say I'm writing a custom tag to handle tax. Not
only am I going to take the time to make it reusuable, I'm going to make sure my
math/logic/etc is correct. Typically the code you should be reusing is the code
that is somewhat important, so the extra time is definitely a good thing.
MS: So are there many new tags you have to learn to write custom tags?
RC: Technically the answer is no. Custom tags are built with simple CFML. There
are a few functions that relate to more advanced uses of custom tags. Again
though - the simple answer is that you don't have to use any special tags to
work with custom tags.
MS: So a new developer can create a custom tag immediately, no learning curve?
What do you have to do?
*RC: I'm not sure I'd say a "new" developer per se - but someone who has at
least basic CFML experience. So, sure, a new developer can use these tags, but
they should at least know a bit of CFML.
MS: What about more advanced developers - can you pass parameters back and forth
to a custom tag?
RC: Yes. A custom tag ends up being like any other built in tag. They can take
arguments, and they can pass results back. We will discuss the "API" for doing
this (trust me, it is simple) as well as some best practices.
MS: So that means you can totally extend the ColdFusion tag language with your
own tags and they will look the same as the build in tags to other programmers?
RC: That's right
MS: Are there any difference between custom tags and built in tags then?
*RC:* Well, some of the tags that are 'built-in' are actually written in CFML,
and you can mimic that functionality, but it isn't supported so I don't
recommend it. As for differences - not really. Custom tags allow for required
and optional arguments - just as built-in tags do.
MS: Can you overwrite built in tags with your own tag definitions - if for
example you don't like how a certain tag works?
RC: Not by any normal means. As we all know, there are things you can do with CF
that aren't exactly by the book.
MS: Hmm, interesting. I will look forward to your talk
|