May 10, 2017 | Written by: Stephen Northover
Categorized: DevOps | Open Source
Share this post:
A common problem for developers is being able to work effectively with and understand large code bases. This problem can affect everyone on a team, whether you’re new or experienced. It’s hard to know every line, and everyone needs to find their way around the code base.
Better not refactor!
The Web IDE to the rescue
Imagine that you’re browsing a code base and you see a function call. You might ask yourself:
“Where is this function defined? Are there multiple declarations? Who else uses this thing? If I change the implementation, who is affected?”
Fortunately, the Eclipse Orion Web IDE, part of Continuous Delivery, has a feature to help in this scenario. It’s called “References.” To use it, click a code element, such as a function call, and select an option from the References menu:
A window opens to show each match, categorized and weighted:
The Web IDE includes a type-inference engine that can determine the type and scope of a function or variable. This information is used to weigh the results.
Here is a handy legend:
- Green check mark: Perfect match
- Blue question mark (?): Potential match
- Red (x): Not a match
Go ahead and refactor
You can refactor the references that you found to the main() function to be main2() by clicking Preview:
A simple rename consists of these actions:
- Finding all of the references
- Inspecting each reference by category, noting any checks and question marks
- Selecting or clearing the replacement check box
- Clicking Replace
Of course, refactoring is more than renaming, but the first step is to find and categorize each match.
You can use the new References feature in the Web IDE to understand how a variable or function is being used. Understanding the code is the first necessary step towards refactoring.