ColdFusion 9 and pure CFScript CFCs

Filed under: ColdFusion

comments (21) Views: 17,848

If you came to ColdFusion from a Java, C++, JavaScript, Actionscript, or any other script based background you might not be aware that ColdFusion has a completely separate syntax. It looks very similar to those other languages but has always been sort of a bastard step-child of the tag based syntax. It wasn't as full featured, and wasn't talked about much. With the release of ColdFusion 9 in late 2009 Adobe made a concerted effort to bring CFScript syntax up to par with tag-based. One of the primary focus points was allowing developers to write ColdFusion Components in pure script. As part of my recent pastebinCFC project, I made the decision to write this new CFC in full CFscript. I wanted to take a short blog post to point out some of the things that I discovered while writing this project.

To start with, CFScript CFCs are much more terse than their tag based brethren. Less code means less typing, which converts to working faster and more efficiently. Let's compare an uber simple tag based CFC with one that's writte in script. Well use a simple bean object which is commonly used in MVC frameworks to store encapsulated data and pass it around.

Update: Dan Skaggs sent over a simpler version of the tag based CFC. I'm adding it here inline. Thanks Dan.

Now let's look at the same CFC written in script, with the same functionality.

Whoa, whachoo talking about Willis? It's less than half the lines of code, and I don't even have method definitions in there for the getters and setters! How's that supposed to work? Well, for starters, in CF9, you can use property to imply properties that comprise your object. In this case we have a string property called username, and another called password. Not only does that define, and create variables for us, but it also type checks them. And with CF9 the ColdFusion engineering team added support for something called implicit getters and setters. This takes every property defined in the object and "writes" virtual methods FOR you. You'd use them the same way.

Not only does it allow me to streamline my code, but you'll notice that when I create a new instance of my object, I don't even have to call the init method. ColdFusion will look for a method named init, and fire it if it exists.

Hope this helps you move forward in your usage of ColdFusion.

Amazon logo

If this article was interesting, or helpful, or even wrong, please consider leaving a comment, or buying something from my wishlist. It's appreciated!

comments powered by Disqus
coach outlet online jordan 13 grey toe beats by dre cyber monday michael kors black friday beats by dre cyber monday jordan 6 black infrared north face cyber monday michael kors cyber monday north face black friday coach outlet black infrared 23 13s north face cyber monday jordan 6 black infrared north face black friday coach cyber monday jordan 11 legend blue north face cyber monday black infrared 6s lebron 12 north face black friday jordan 11 legend blue louis vuitton outlet jordan 13 grey toe grey toe 13s beats by dre black friday coach black friday jordan 13 grey toe coach cyber monday uggs black friday jordan 13 black infrared 23 uggs cyber monday barons 13s uggs black friday beats by dre cyber monday black infrared 6s jordan 13 bred jordan 13 black infrared 23 north face black friday black infrared 6s jordan 11 legend blue michael kors black friday jordan 13 grey toe coach black friday michael kors black friday michael kors cyber monday beats by dre cyber Monday north face cyber monday coach black friday michael kors cyber monday beats by dre cyber Monday north face black friday beats by dre black friday lululemon black friday uggs black friday jordan 13 bred coach cyber monday beats by dre black friday uggs black friday coach black friday black infrared 6s