Matt Gifford aka coldfumonkeh | Consultant Developer
View Github Profile


ColdFusion Builder - Refactoring Explained

Mar 25, 2010

ColdFusion Builder has a built-in operation to perform refactoring tasks, another tool to help alleviate mass problems with renaming and any conflicts that may arise - no one steps into the world of refactoring without a mild sense of fear and possibly perspiration.

What is refactoring?

The official (or 'an' official) definition of refactoring:

"Improving a computer program by reorganising its internal structure without altering its external behaviour"

More specifically, the ability to successfully rename files, functions and methods throughout an entire project or application without damaging or breaking the underlying code and functions.

ColdFusion Builder has a built-in operation to perform refactoring tasks, again helping to alleviate mass problems with renaming and any conflicts that may arise - no one steps into the world of refactoring without a mild sense of fear and possibly perspiration.

Renaming CFC or CFM files

From within ColdFusion Builder, you can easily rename a .cfc or .cfm file, which will alter all references pointing to or using that particular file.

Within the root of my project, I have a file called monkey.cfm - this has clearly been misspelt, and MUST be changed to monkeh.cfm immediately. Luckily, it's VERY easy to do using the refactoring option available.

  1. Select the file you wish to rename from the Navigation pane
  2. Right-click and within the context menu select Refactor > Rename

This will open up a dialog window to enter in the revised name of the file:

renameFile1

Once the correct or revised file name has been added, you have the option to make changes to only the current file.

By default this is unchecked, as refactoring normally indicates changes are required across the entire application - besides, prudence and caution should advise you that it's always better to scan across the entire application anyway to avoid any possible issues later on.

Click the 'Preview' button, which will load up the next screen to show you a list of files and the code lines where changes will be made, also providing a superb code-comparison window:

renameFile2

In this example, only one reference to the file was found, which was the cfinclude path in index.cfm. If you're happy to commit the changes, click 'OK' to confirm. ColdFusion Builder will make all of the necessary changes and your work here is done.

Renaming UDFs

UDFs are likely to be used throughout an application on numerous pages. Revising the name of the functions is incredibly easy.

  1. Open up the file in ColdFusion Builder, and select the function name
  2. Right-click to pull up the context menu and again select Refactor > Rename

In this example, I have a ColdFusion function written in the index.cfm page. The included monkeh.cfm page also makes a call to the function getDateTime().

I want to change this to getNow(), so highlighting or selecting the existing function name, select the 'Refactor' menu option. You will again be greeted with the internal refactoring dialog window. Enter the revised name for the function.

UDFRename1

To see all changes across the project, click the preview button, which will list and display the location and specific entry of code to be changed.

UDFRename2

In this screen shot, you can see that ColdFusion Builder has found that the function is being called in both the index and monkeh.cfm files, and that the function itself is written in index.cfm, which will also be renamed.

Clever ColdFusion Builder.

Reference Searches

Renaming and revising file, function and method names aside, another essential tool of project and application management is the ability to search throughout the code base.

Guess what? ColdFusion Builder has got that down for you as well.

You are able to search for a reference of a file within either the project or the workspace.

  1. Within the Navigation pane, right-click on a .cfm or .cfc file within the project
  2. Select the 'References' option, and choose either 'Project' or 'Workspace'

reference1

If it's not already open within your ColdFusion Builder workspace, the Search window will open and display all locations of the referenced text within either the entire workspace or the current project, as selected in the previous step.

You are also able to run a reference search within a particular file. With that .cfm or .cfc file open within the code editor window, select or highlight the text you wish to search for, and under the 'References' context-menu, you will now see a third option to search within the file, as well as the project or workspace.

Simplified Refactoring

For me personally, I have found the addition of the refactoring functions in ColdFusion Builder another great tool and a benefit to development.

As code bases grow and expand over time, amending applications and object references can turn into a major chore. Refactoring can now be achieved through the IDE, helping to alleviate the risk of damaged references and file paths, which otherwise could have potentially disastrous effects on your application.


Latest Blog Posts

Jul 16, 2020
Github Actions with CommandBox and TestBox
Read More
Jul 9, 2020
Azure pipelines with CommandBox and TestBox
Read More
Dec 23, 2019
CFML content moderation detection component library
Read More