Skip to content
SciTools Blog
Menu
  • Home
  • Blog
  • Support
  • Contact
  • Login
  • Pricing
  • Free Trial
Menu
black and silver claw hammer

Cool Plugins for Code Maintenance

Posted on May 13, 2022

Abstract: Three plugins provided by our partner, TechMatrix, that can help you identify and visualize code with low maintainability.

TechMatrix
Techmatrix, our long-time distributor (and friends) in Japan wrote these scripts and shared them with us. Dōmo arigatō

I’ve worked on Understand long enough to know a few areas of the source code I’d rather not touch. The entity locator is one of those areas. I think the design was intended to make it easy to add new locators by separating the logic across an inheritance tree. But the net result is that I’d rather avoid touching that code if at all possible. 

The Entity Locator – Fun to use, awful to edit

What if you haven’t been working on your source code for very long? Or, even if you have, maybe you have to work in a messy area of the code anyway. TechMatrix, our Japanese distributor, provides some custom plugins you can use to help identify and visualize low maintainability code.

Identifying Problematic Functions

What makes a function hard to maintain? The TechMatrix “Low Maintainability Functions Report” plugin uses three metrics to identify those functions. 

  1. Cyclomatic: the McCabe Cyclomatic complexity which is the number of decision points plus 1.
  2. CountLine: the total number of lines in a function
  3. MaxNesting: the maximum nesting level of control constructs such as if, while, for, switch, etc.
File Icon
LowMaintainabilityFunctions.upl

To install this (and any other plugins), simply drag the .upl or .upy file into the Understand Gui. You’ll get a prompt to edit or install the plugin. Selecting install will copy it to the appropriate directory. See this article for more information on where plugins are installed.

The prompt when dragging a .upl or .upy file onto the Understand Editor to install or edit.

Because this report is global (running for an entire project instead of a specific entity), it’s found in the Project -> Interactive Reports menu. 

Global Interactive Reports appear under Project -> Interactive Reports

Custom reports like this can have options. In this case, you can specify the threshold value for each of the three metrics:

The Low Maintainability Functions report options dialog

Then, an iReport window will open containing the results:

The Low Maintainability Functions results window

The name of the function (in blue) is a link. Clicking it will sync the entity to other Understand windows such as the information browser. Metrics that didn’t pass the threshold are highlighted in red. The report is comma-separated so it can be opened in Microsoft Excel. 

Identifying Problematic Classes

TechMatrix created a similar plugin for low maintainability classes. The three metrics used are:

  1. CountDeclMethod: the number of local (not inherited) methods
  2. CountClassCoupled: the number of unique classes that type this class or use data or a member from this class.
  3. PercentLackOfCohesion: 100% – average cohesion. Cohesion is calculated for each instance variable as the percentage of member functions that use it.
An example results window for the Low Maintainability Classes report
File Icon
LowMaintainabilityClasses.upl

Visualizing Code

Understand has lots of built-in graphs that can help you identify questionable areas of code. For example, the Control Flow graph is a great place to start. It lets you find areas in a function that can become their own functions. 

A portion of the control flow graph for gnu.getopt.Getopt.getopt, the third function listed in the functions report.

When the built-in graphs don’t meet your need, you can also create your own custom graphs. For classes, TechMatrix provides a custom graph plugin “Calls and Refs Class Internal Graph”. It is designed to showcase the three metrics in the “Low Maintainability Classes” report.

File Icon
CallAndRefsClassInternal.upl
The graph produced by the “Calls and Refs Class Internal Graph” plugin for gnu.regexp.CharIndexedInputStream
The legend for the “Calls and Refs Class Internal Graph” plugin

After installing the plugin, access it in a class entity’s context menu under the Graphs submenu. CountDeclClassMethod is the sum of blue outlined member functions. CountClassCoupled is shown by the dark gray external classes connected with dashed gray lines to the initial class. Finally, PercentLackOfCohesion is related to the number of blue edges connecting member functions to member objects.

Just like TechMatrix, you can customize the data from Understand to return exactly the information you need in whatever format you want using our APIs. Dive in!

  • Instagram
  • Facebook
  • LinkedIn
  • Twitter
  • YouTube

Learn more about Understand's Features

  • Dependency Graph
    View Dependency Graphs
  • Comply with Standards
  • View Useful Metrics
  • Team Annotations
  • Browse Depenedencies
  • Edit and Refactor

Related

  • API
  • Architectures
  • Business
  • Code Comparison
  • Code Comprehension
  • Code Navigation
  • Code Visualization
  • Coding Standards
  • Dependencies
  • Developer Notes
  • DevOps
  • Getting Started
  • Legacy Code
  • Licensing
  • Metrics
  • Platform
  • Plugins
  • Power User Tips
  • Programming Practices
  • Uncategorized
  • Useful Scripts
  • User Stories
  • May 2025
  • January 2025
  • December 2024
  • November 2024
  • August 2024
  • June 2024
  • May 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • April 2023
  • January 2023
  • December 2022
  • November 2022
  • September 2022
  • August 2022
  • May 2022
  • April 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

©2025 SciTools Blog | Design: Newspaperly WordPress Theme