August 4, 2022
ACF Builder Extension: Code Refactoring
Comments
(0)
August 4, 2022
ACF Builder Extension: Code Refactoring
ColdFusion developer for 20+ years, professional experience in 10 other languages & frameworks. Artist, nerd, Jeep enthusiast.
Explorer 24 posts
Followers: 9 people
(0)

Adobe ColdFusion Builder Extension for Visual Studio Code

“Code Refactoring”

What is “code refactoring”? Is it a cool new UK reality show where you win prizes by changing up your applications to work better? No, but if any tv producers from the UK read this and are interested, call me.

Code Refactoring, put simply, is improving your code by altering things like naming conventions, readability, and other factors that make maintainability of your code better over the long run. This can be done manually, of course, though that introduces the potential for mistakes, missed items and the like, which can introduce unintended bugs into your system. We only want the intended bugs in there!

The ColdFusion Builder extension includes several tools which can help out with your refactoring duties. One of the most basic items in refactoring is renaming. Renaming of variables, components and even pages. In other, less capable IDEs, you could simply do a find-replace, but this can introduce serious issues.

For example, let’s say you included a variable in your code called “system”. As it turns out, this is not a good variable name for a number of reasons, and your lead dev asks you to rename it to “ofadown”. As one does.

If you simply did a find and replace, it would replace EVERY instance of that word throughout your project, including simple text! That won’t do at all.

Since the Builder extension recognized this as a variable, right clicking it and choosing “rename symbol” would allow you to rename just the instances of this variable, ignoring other instances such as comments or plain text in HTML.

A similar functionality exists for renaming CFCs and CFM files. Right clicking the file name in the project list and selecting “rename” will not only rename the file, but it will rename all references to the file throughout your project, saving you time and reducing the potential for error. While you’re doing this, you can also preview the changes which will occur due to the change, allowing you to be extra diligent in your refactoring.

Part of refactoring also includes finding references to functions and variables (and even pages!). It is important to know where they are being used (or IF!) and the extension gives you the option to see just that.

If you right click on a function, variable or page, you can select “find reference” for the item in question. This will provide you with a list of where that item is being utilized.

From that list, you can then utilize the “rename” functionality, or just make sure you know where your items are being used throughout your application. This can help you with documentation as well as simplifying your code for better long term maintainability.

0 Comments
Add Comment