The Future of ColdFusion Part 2
In my last article we looked at some things that Adobe is doing to further the advancement of ColdFusion. In this article I want to take a sneak peak at the next version of ColdFusion (CF 9) currently code named Centaur. First we are going to look at a series of language enhancements that will help build a better ColdFusion.
The first is to fill in the gaps with cfscript. One of the ideas behind this is the ability to write your components just using cfscript. I blogged about this awhile ago and I am really happy to see this enhancement. I know others have told me (or commented) that they are not a big fan of this and my answer to you is OK. This will change nothing in your day and you will still be able to write you components using tag syntax. What this does do is provide another solution for those of us who want to use it. I understand that declarative syntax makes things a heck of a lot easier for us but it also adds tons of typing. Creating components for me is going to get a lot quicker with this new feature. Adam threw up a slide and the code looks like the example below. While this is not the most logical code (I know its just an example) it does look sweet. He also added that passing methods will be fully supported.
The next enhancement was the new explicit local scope. Anyone who has written a component knows that writing private variables is kind of "weird". Right now you have to use the var keyword and you have to set it at the top of your function. The var scope is where the weird comes in because it is like no other scope in the language. There is no collection for the var scope like there is with session or event the arguments collection. Moving forward you are going to use the local keyword to declare private variables and the good thing is that the scope can be used throughout the function. For your existing code that does use the var scope ColdFusion will auto magically place those variables into the local scope. Staying with that theme they may add a feature to set a default scope for a component. We have all come across memory leaks in a component that usually come from a variable not being declared private to that function. With the new feature you will be able to tell the component that the default scope is local and if a variable is not declared it will be set into that scope. I don't have any inside information to how the syntax will look but here is and example of what our new component could look like. The nice thing about this example is we could eliminate the need to declare a scope for our query name. This has always frustrated me because I can think of no situation where I would want that variable to be anything but private. If another method has to access the query there are much better ways to go about it.
Next the cfcontinue and cffinally tags are going to be added. The continue just allows you to break a loop and jump back to the top. In the past we would usually write some kind of if/else statement to get out and go back now we can just use cfcontinue. The finally tag will always run after a catch. This is pretty common among other languages so its a welcomed addition. The one thing that Adam brought up that I thought was kind of cool was that cfcontinue is already a part of cfscript and will be the first method to ever ported from script to tag.
Next is the addition of the new & import keywords. The new keyword will allow you to create objects with very little sytax. With that is the addition of the import keyword which will allow us to treat our components in more of package format. Along the same lines is Implicit constructors. Right now everyone just kind of follows the guideline of using the name init as a constructor. With this though you usually have to call the constructor, in the future this will change. There are a couple ways we can go about doing this. The first is sticking with the init name so that code we created before will still work. Next we can use the name of the cfc, so if our component is users the function users will be our constructor. Finally we can tell the component what method to use as the constructor by defining it in the component by saying <cfcomponent init="name_of_constructor". If we look at the code below you will see it makes it easier to create objects.
Next Adam started off by saying that this was long overdue and he was right. Implicit getters/setters will be a great addition and cut down on coding value objects. By using the cfproperty tag and setting accessor="true" we will know that there are getter and setter methods for the property. The important thing to note here is that its not generating code for you, that object will just implicitly have the getter and setter methods. Also if you already have getters and setters it will use your methods and ignore the implicit ones. Here is a quick example of what our user component might look like.
Next is the new Server component. This component will be defined per instance and contain a couple of handy methods; onServerStart & onServerEnd. All application components will inherint from the server component. The next two actually need their own post. Any comments on any of these exciting enhancements are welcomed.
