Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
What is Developer Zone?
United States

Document TypeTutorial
NI Supported: Yes
Publish Date: Jul 31, 2009


Feedback


Yes No

Analyzing Code Complexity with VI Analyzer Toolkit

2 Ratings | 5.00 out of 5
Read in | Print | PDF

Overview

Understanding the complexity of large applications can be a challenge for developers. Various factors contribute to the quality of the code and the complexity of the project, but the ability to identify these factors mitigates the risk of problems that can lead to unexpected behavior or significant increases in time spent isolating bugs. The LabVIEW 2009 VI Analyzer Toolkit features five new tests that provide developers with metrics to measure the complexity of code and suggest specific actions to improve the maintainability of the VIs.

Table of Contents

  1. Cyclomatic Complexity
  2. Other New Metrics
  3. Related Links

Cyclomatic Complexity

Cyclomatic complexity was invented by Thomas J. McCabe in 1976 to provide a metric for software quality.  The cyclomatic complexity metric measures the number of linearly independent paths in the block diagram code. It gives an indication of the amount of branching in the code and the recommended number of tests for the VI.

The cyclomatic complexity of a software module is calculated from a connected graph of the module (that shows the topology of control flow within the program):

Cyclomatic complexity, M = E − N + 2P, where:
    M = cyclomatic complexity
    E = the number of edges of the graph
    N = the number of nodes of the graph
    P = the number of connected components.

Figure 1: This diagram shows the connected graph for the corresponding block diagram code that was used to calculate a cyclomatic complexity of 4

Generally, the value of M, the cyclomatic complexity, should be below 20.

Other New Metrics

Depth of Nesting of Structures - Checks that the nesting of structures is within the user-specified limit. This defaults to 6.

Fan In - This test checks if the number of VIs calling this VI is less than the user specified number.

Fan Out - This test checks if the number of SubVIs called by a given VI is less than the configured value.

Modularity Index - Checks that the Modularity Index for the VI is above the user-specified limit. The Modularity Index measures the ratio of number of SubVIs vs total nodes in the block diagram excluding the terminals of front panel objects. It gives an indication of how Modularized the VI is. It is desirable to have larger value for Modularity Index.

Related Links

To see everything that's new in LabVIEW, visit ni.com/labview/whatsnew

To try this and other new features, download LabVIEW to evaluate it for free

Learn more about VI Analyzer here.

2 Ratings | 5.00 out of 5
Read in | Print | PDF

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).