Scopes in CFC

I know there is always a load of talk (and even arguments) about the various scopes inside a CFC.
Brian Kotek has just posed the Definitive guide on CFC Scopes.

this is a must read for anyone that writes CFCs


Speaking at WebDU 2007

Once again the great folks at Daemon are putting on webDU 2007 and Geoff dropped me a line to say that I was going to be speaking once again at this great conference.

I will be speaking about Instant messaging and CF, so get ready for some little bots answering silly questions over IM as I prepare!

If IM is not your thing, I will be sure to see you in a bar somewhere to chat about anything, it was a blast last year and I am sure it will be again this year.

WebDU Banner

Whitespace and CFC

Continuing along the whitespace theme, it is time to look at CFCs.
CFCs give the ColdFusion programmer a level of abstraction that they have been craving since just after the introduction of the custom tag. They are great for encapsulating away some of the messier business logic in our applications and help keep the weight of our actual cfm files down.

Unfortunately when it comes to whitespace, they can be just as bad as putting all that logic at the top of the page as by default the do nothing to help suppress whitespace, they just dump it all to the page.

Luckily there is a property on the cffunction tag that tells it to suppress all output from within the function call itself. Just simply add output=”false” to all of your functions and you will notice a dramatic reduce in the amount of whitespace returned to your page by your custom functions.

What if my function outputs html code? Well this will force that HTML code not to be returned to the browser so you will need to make sure that you do not turn it on if you have your presentation layer code inside your CFC.

You can also get whitespace from the lines in-between your functions in your CFC, so if you have really well spread out CFCs you will want to add output=”false” to the cfcomponent tag as well to make sure there is not extra space dumped out when you instanciate your cfc

How can I see how much whitespace is in my CFC? Well the easiest way is to just test it… get a blank page and call it like so.

test = createObject("component","testCFC");

Then view the source and count the lines between the comments. There should be just one. Now you know that there is no whitespace between your functions. The next step is a little harder, you need to repeat this process for every funciton in the CFC. Yes, it is a little over the top but if you are seirous about reducing you page weight this is the way to do it!.

ColdFusion and Whitespace – Part 3

So far we have looked at ways of controlling chunks of whitespace inside a page but many developers find that most of their cfprocessing and therefore their whitespace is at the top of their page. This is great from a whitespace suppression perspective, we can just reset the output buffer. You can do this with cfcontent and the reset option <cfcontent reset=”true”> will erase everything in the output buffer.

Christian Cantrell posted way back in 2003 of a great little way to access the underlying Java architecture of CF to do the same thing.


There are a few other neat tricks out there to help you put your CF output on a diet.
We use CF_Accelerate all over the place to cache some of our slower code. As well as doing that, it can also clean out some of the whitespace in the cached content before it is cached.

Now that we have the tools to help us attack whitespace, lets have a look at some examples of good and bad code from a whitespace perspective.

The main cause of whitespace is the gaps between tags. When you end a tag, CF looks a the gap between it and the next tag and it decided that this is not CF code to be executed and thus returns it to the browser.

Below is a simple loop that displays a users name if the display flag is set to true. If you were to run this on a standard cf page you would get about five blank lines between each name. These come from the tabs and the new line characters around the ColdFusion tags.

#q.firstname# #q.lastname#

Lets use cfsetting to put this on a diet

#q.firstname# #q.lastname#

Now as Jeff Coughlin pointed out in his comment to part 1, this is very old school – it was the sort of stuff I was coding back in CF4.5 to reduce the whitespace in my pages but it is still very valid today. Yes it does make it a little more code when you first write it but it much lighter.

If you want to go one step further, CFScript is the ultimate in control. Only the characters that you tell it to return make it to the browser.

for(i=1;i lte q.recordCount;i=i+1)

" & q.firstname[i] & " " & q.lastname[i] & "


I am sure that someone is going to tell me I could have removed some of the formatting in this example and brought it down to just three lines of code but I wanted to put it all in so you know what you are getting into if you take the cfscript route.

How do I make the choice? Well for me it is easy. If there is a chunk of code that generates a tonne of whitespace and it is on every page then it is a candidate for converting into either straight CFScript or some for of serious whitespace suppression.

Take the calendar on this page, it uses a lot of whitespace. The whole control is dynamic so why not write it in cfscript. It will take some time to get it just right and it will not be as easy for novice ColdFusion developers to debug but it will be much lighter on your page.

The next target on our whitespace hitlist will be CFCs so stick arround…

ColdFusion and Whitespace – Part 2

Continuing on the ColdFusion whitespace hunt, your next weapon is the <cfsilent> tag. This is my personal favourite as it is the most straightforward. You just wrap the cfslient tag around anything and it tells ColdFusion not to output anything to the browser from within it.

... something that has a lot of whitespace in it ...

It also has its own little trap, it does exactly what is said it would – it does not return anything from with in it, so you have to be a little be careful when debugging as you can often get trapped trying to output hints or the contents of variables to your web page and not see it.

Moving onto the cfprocessingdirective tag. This could be the most complicated way of getting whitespace out of our code. Like the cfslient tag, you will need to wrap the code that you want to bring under control

... your code goes here ...

This tells CF to suppress the whitespace characters that are generated by CF. The good news is that if you need to actually include the whitespace you can nest the cfprocessingdirective tags and turn whitespace suppression off again. ( I am still looking for a good reason to do this though)

Next, using java to control the output buffer.

ColdFusion and Whitespace – Part 1

I know quite a few CF developers who are happy if their code runs, then there a the developers who watch the time that it takes for their code to run, down to the millisecond to make sure that their site is as fast as it can be but there is more to a web page than the time it takes to execute. Of course, this is important but there are other things that can speed up or slow down your page beyond your CF code.

The most often forgotten is whitespace. It is all the extra space that is in between your HTML code, typically it is just tabs, spaces and new line characters but these all add up when it comes to the size of the page that you return to the browser. If your page is 100k and 10% of it is whitespace. If you remove this extra 10k, you can get an easy performance jump from your server – it will be able to output 10% more html without using any more bandwidth. Simple math really.

Over the next few days, I want to dig into a few different things you can do to keep it down.
The first and most easiest thing to do is to turn on the ‘Enable Whitespace Management’ feature inside the ColdFusion Administrator (it is on the settings page) This is basically a must have for any production environment. Like every setting you do need to consider how much of a performance impact this will have on your app but I have never found this to be enough of a load to warrant it being turned off.
In your development environment however, this is something you will want to keep turned off. You will want to see just out much whitespace your code is pumping out without it so you can go to work on it at the source.
The next thing to add to your arsenal is <cfsetting enablecfoutputonly=”yes”>. This tells ColdFusion to only return to the browser things inside tags. There is one drawback to this technique is that it cascade down through a request. Why does it do this? Well it is a setting, so it is turned on and off at the request level. If you turn it on (or off) in an include or a custom tag, it will affect the whole request.
To make things a little more confusing, it is also accumulative, if you turn it on twice in one request, then you will need to turn it off twice in the same request before ColdFusion will behave like normal. So the best thing to do is make sure you turn enableCFOutputOnly at the end of any file that you turn on in.

On the ever present performance question, yes this does impact performance, again not by much but you do need to understand what is happening if you wrap every last bit of HTML code in an output tag to ensure that it makes it to the page. The tag tells CF to look closely at this and try to execute it. Now this is only affects the first load of a page, when CF complies it to java byte code, so if you notice it, you are doing better than me!

Tomorrow, in the next post, we will tackle cfsilent and cfprocessingdirective…

The ColdFusion bounty hunt continues…

It is one day after the launch of the ColdFusion Developer Bounty hunt and we are still looking.

I know that it takes time for things to trickle through the internet so I am not getting my hopes up just yet. There have already been quite a few questions from all over the place, Brisbane to Melbourne and as far away as London but no resumes! So in answer to your questions…

  1. Is this real? Yes most defiantly. I need a CF developer!
    Yes, the position real. You can find it on (minus the bounty)

  2. I am a recruiter; can I find you a candidate? Yes of course! Recruiters are the modern day bounty hunters! The bounty is still the same; no additional fees will be paid.

  3. Is this really real? Once again, most defiantly yes. There are enough internet stunts that have worked (just look at the red paperclip) this is no different.

Tell your friends, tell everyone – the bounty is waiting to be claimed.

ColdFusion Developer Bounty

It appears that it is the season for CF developers in Australia at the moment. There are CF positions being advertised in Melbourne and Adelaide and even in Newcastle at Teligence! It is great to see this nice new interest in CF developers. We have just taken on another CF junior and are about to start training them up (It is nice to have a CF instructor in house)

With 80 odd CF positions currently on Seek around the country, I get just a little concerned for our own team, so whilst we are on the recruitment drive, lets keep going… I know most people who might read this are really happy with their current CF position but I know you all know someone who might not be so happy.

So here is the deal, RedBalloon is an Experience company and I want to share the love – if you find me the perfect CF developer, I will ensure that you get an experience you will not forget, Jet Fighter flight sound good? Find me a senior CF guru! Know an up and coming CF legend? V8 hotlaps it is for you! I could go on but let it be know that the bounty is out there; Find Lucas a CF developer and you will be on an experience you will not forget in a hurry.

Yeah, gotta put some terms on an offer like this – there is only one experience available per SUCCESSFUL applicant and the value of the experience will be directly related to the value of the successful candidate. When that person starts, you will hear from me and we will work out something for you to do, right then on the phone!

Oh and the applicant doesn’t miss out either – they will be working for RedBalloon, how could they possible miss out! We just took the entire IT team Jet boating last Friday (Ryan could not believe it, he has only been with us two weeks)

On to the position, I will take almost all comers but I am looking for a senior CF developer who can work full time in Pyrmont, Sydney, Australia. Someone who can tackle a project head on, someone know can help lead the rest of our team to greatness. We currently have 7 different projects that need work so there is no lack of variety of things to work on.

Skills? There is no long list here, just know CF 7 at a Guru* level – no minimum number of years experience (you can learn all you need to know about CF in 6 months if you don’t sleep) but you will be asked as part of the interview process to prove that you do have what it takes to be a Guru.
* All Gurus know about CFCs, the know about XML, they know about SQL and CSS.

Who is RedBalloon? We are a four year old startup that has been growing at 100% per year from day one. We work hard but we value balancing your work live and your personal life. We are driven and focused and you will always know where you stand and what you need to do today. We pay well and commit to your ongoing personal and professional skills development.

Know someone who fits the bill? Want to claim the bounty? Email me lucas @ redballoon .com .au now!

Know CF? Want to work on my team?

Unfortunately, one of our developers, Andy is moving to greener pastures, so we now have yet another spot for a ColdFusion developer.

Got Talent? Think you can cut it working with a very fast moving development team? We do at least one release a week so there is defiantly no time wasted.

We also play just as hard as we work, Andy has just come back from a shark dive and I have just taken a classic MGB away for the weekend all on the company’s dime.

Sound interesting? Read on for the formal bit..

ColdFusion Security Bulletin

this goes in the “doh” sever configuration department, If you had not already worked it out, the createObject function in ColdFusion does allow developers to create potentialy unsafe code as they can use it to create instances of the factory object that is use internally by the ColdFusion administrator.

The CFOBJECT tag and CreateObject functions should be secured in a shared or untrusted developer environment.

By default, the CFOBJECT tag and the CreateObject function are accessible to all ColdFusion developers. This tag and function should be secured in a shared or untrusted developer environment.

If you need to know more, check out the security bulletin