May 29, 2018 5:39:08 PM by Clarisa Maman Orfali
In this article, we will learn to analyze code using the Toad Code Analysis diagnostic tool.
This tool shows a series of industry standard metrics that are very useful to determine the following:
For example, this tool can be used by a project manager to assign developers for a new project. These reports can quickly assess the type of code and help the project manager decide who, in terms of skill level, would be required for the project.
On the other hand, developers can use this analysis tool to establish, for example, a reference status of the code they are about to work on and then compare it with the same elements of the report once the programming task has been completed.
This information provided by this tool can be used to help developers make sure they don’t make any mistakes. This feature can also be used to evaluate software packages based on the Oracle code and compare the code between the solutions being considered.
Next, we are going to open this tool in Toad for Oracle.
We select from the Database menu > Diagnose > Code Analysis:
We can analyze packages, functions, and procedures. For example, for this demo we will work on the analysis of a package called MINUEVOPAQUETE.
To load all the packages that we have available in our schema, we select the "Load Objects" icon.
Then we select “Load My Packages”.
We select the package that we want to analyze. We can see two panels open: On the left side, we see the “Results tab” of the selected package, in which the analysis results will appear after we run the tool. On the right side, we can see the package code. In this example we are going to analyze a simple package as a demonstration.
In the “Report tab”, which is located next to the “Results tab”, we can see a Table of Contents.
This table of contents shows us the definitions of the metrics used by this analysis tool. Each of the metrics is explained in the table of contents in terms of how they are used by the tool.
- n1 = the number of distinct operators
- n2 = the number of distinct operands
- N1 = the total number of operators
- N2 = the total number of operands
Knowing these metrics, we are able to perform the analysis of our package.
We go to the “Results tab”, having selected the package we want to analyze.
We click on the green triangle button "Analyze code for all selected items"; or, we can press the F9 key.
When executing the analysis of the package we can visualize the metrics in the Results tab:
- Halstead Volume: 27 (code easy to maintain and understand)
- McCabe’s Cyclomatic: 2 (It’s a very simple program)
- Maintainability Index: 122.17 (Easy to maintain code)
- Toad Code Rating (TCR): 1 (a simple classification by Toad that has 4 possible values: from 1 to 4, with 1 being the best and 4 being the worst)
At first glance, with this analysis we can determine that this code is easy to maintain and easy to understand by the developer. Then, the project manager can select which developer is appropriate to maintain the code.
We will quickly analyze another complex code, in this case the package is called EBA_PROJ_STATUS_API.
We can observe the values of the following metrics:
- Halstead Volume: 1,667 (code is a bit more complex, more challenging and it would take a bit more of the developer's skills to be able to change the content of the code)
- McCabe’s Cyclomatic: 26 (it's a complex program)
- Maintainability Index: 59.08 (the code is difficult to maintain)
- Toad Code Rating (TCR): 3 (Toad gives us a simple classification)
In addition to the code metrics we have a lot of information in the results tab, such as the Summary, Rule Violations, and Properties, which shows information about cursors, declarations, DML analysis, function analysis, procedures, etc.
An interesting section of the summary is the Module Analysis, which shows us at a glance the number of comment lines, the number of executable lines, the total number of lines, the number of declarations, the number of DML type declarations, etc.
Finally, we can see in the grid all the most important metrics of the packages we have just analyzed, highlighted by colors, which allows us to quickly see if the code is easy or not to maintain by the developer.
I invite you to use this great tool that Toad for Oracle provides us to analyze our code and know more about how we develop our program modules.
Tags: Toad for Oracle
Written by Clarisa Maman Orfali
Clarisa is from Argentina. She is Founder and Director at ClarTech Solutions, Inc. a company dedicated to the development, consultancy and training in Information Technologies located in Southern California in the United States.
She is a Systems Engineer with more than 18 years of experience in systems development. She was introduced in Oracle Technologies in 2009, a few years later she discovered the great power of development with Oracle Application Express (APEX) and has specialized since then in that area.
She is also Co-Founder of the Oracle Users Group of Argentina (AROUG) and founder of Oracle APEX Latin America meetup, has also actively participated in the organization and as Presenter of big and popular events such as the OTN Tour and the Oracle APEX Tour of Latin America. In 2014 was recognized by the Oracle Corporation with the Oracle ACE Award. Then, in March 2018, she was promoted to Oracle ACE Director.
She is also the author of the first three books in Spanish about Oracle APEX: