ColdFusion Builder - Refactoring

This post is more than 2 years old.

I don't know about you - but every time I hear about refactoring in an IDE, I break out in a case of the cold sweats. It's the same way I feel about multi-file search and replace. Sure it's a great feature, but the idea of updating hundreds of files at one time and not screwing up just freaks me out. That being said, I decided to just get over my fears and take a quick look at refactoring in ColdFusion Builder. To be honest, I would not have played with this feature at all if I hadn't discovered that it has a preview function. So if the thought of accidentally spreading a typo across a thousand files worries you as well - at least know that you can see exactly what changes will be made before committing to actually modifying your files.

ColdFusion Builder supports refactoring in two main areas. Let's begin by looking at the first - file renaming. If you right click on a file in your project, you can select Refactor/Rename. In my first experiment with this feature, I tried to rename org/camden/blog/blog.cfc to xxblog.cfc:

I clicked preview and got the following:

As you can see, there is a list of 'tasks' that includes both the file rename and code changes. Notice that it detected that blog.cfc used it's own name in the return of the init method. It correctly knew that it needed to rename the type. Unfortunately, it did not recognize the fact that my Application.cfm file had a createObject pointing to the CFC. So in this case, it wasn't perfect.

I then tried a second test - a rename of my layout.cfm custom tag, which is used in many places:

This time it seemed to work perfectly. It caught all the files making use of the custom tag. Also note the checkboxes. I could selectively turn off any modification if I see a potential problem. All in all, a pretty cool example!

The second place you can do refactoring is with UDF/CFC method names. So for example, consider the renderEntry method in BlogCFC. It is the core blog entry rendering method and its called in quite a few places. I opened up blog.cfc in my editor, found renderEdit, right clicked and selected Refactor/Rename again. For my new name I picked renderSexier:

Again, it looks to me like it successfully found the uses. Do folks think they would make use of this?

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by John Sieber posted on 3/11/2010 at 2:16 AM

Great post and yes I would really like to use it, but also feel nervous when making a large number of changes like that. I always thought that I was a little paranoid, so it is nice to see that others have concerns as well. In a perfect world this is a really nice feature.

Comment 2 by Justice posted on 3/11/2010 at 3:50 AM

Cold sweats? Are you using a source control system?

Comment 3 by Raymond Camden posted on 3/11/2010 at 3:51 AM

@Justice: Absolutely. And yes, it still makes me nervous. ;)

Comment 4 by Marko Simic posted on 3/11/2010 at 8:42 AM

@John I used this feature in java, as well in CFB and it never caused any problem. And if and when waste hits the fan - god bless source control.

Comment 5 by Upendra Roul posted on 4/25/2013 at 3:23 PM

Very informative.