Apparatus and method for indicating program comprehension difficulty

The program comprehension difficulty indicating device addresses the limitations of existing metrics by calculating and aggregating identifier metrics within and across program scopes, enhancing readability and maintainability through precise difficulty assessment.

JP7794707B2Active Publication Date: 2026-01-06HITACHI LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
JP2022115138
Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
Filing Date
2022-07-19
Publication Date
2026-01-06
Estimated Expiration
2042-07-19

AI Technical Summary

Technical Problem

Existing software metrics fail to accurately assess the ripple effect of code modifications on program comprehension difficulty, neglecting the relationships between modified parts and the entire program.

Method used

A program comprehension difficulty indicating device that calculates and aggregates identifier metrics within and outside an evaluation range, considering the entire program, and incorporates identifier similarity to refine the assessment.

Benefits of technology

Enhances program readability and maintainability by quantitatively indicating comprehension difficulty, aiding in identifying and addressing difficult-to-understand code sections, improving development efficiency and reducing maintenance time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007794707000003
    Figure 0007794707000003
  • Figure 0007794707000004
    Figure 0007794707000004
  • Figure 0007794707000005
    Figure 0007794707000005
Patent Text Reader

Abstract

To provide a program comprehension difficulty pointing-out device and method which quantitatively point out an index relating to the difficulty of program comprehension which becomes a factor of decreasing the maintainability of a source code in a software development to develop a program with excellent legibility and maintainability.SOLUTION: Processing by a program comprehension difficulty pointing-out device obtains an identifier metrics for each identifier within an evaluation range of an identifier that appears in an evaluation range of a source code to be analyzed, an identifier metrics for each identifier outside the evaluation range of the identifier that appears in the evaluation range, and an identifier metrics for each identifier of the identifier that appears in the entire program. The identifier metrics is, for example, the number of times of appearing for each identifier. The identifier metrics for each identifier subjected to each aggregation is aggregated for each statistic item, such as an average value and the maximum value. A program comprehension difficulty in the evaluation range is calculated in accordance with the aggregated value of the identifier metrics for each identifier and the linear sum of each weighting coefficient, and is displayed in accordance with each evaluation range.SELECTED DRAWING: Figure 8
Need to check novelty before this filing date? Find Prior Art

Description

[Technical Field]

[0001] The present invention relates to a program comprehension difficulty indicating device and method, and more particularly to a program comprehension difficulty indicating device and method that quantitatively indicate an index relating to the difficulty of program comprehension, which is a factor in reducing the maintainability of source code in software development, and are suitable for developing programs with excellent readability and maintainability. [Background technology]

[0002] Computer software is at the heart of our information-processing society, and software development requires effective use of human resources to develop high-quality software at low cost, on time, and with efficient maintenance.

[0003] Therefore, regardless of whether the source code is written in a high-level language or in assembler, the readability of the source code is an issue throughout the entire software lifecycle, including source code creation, debugging, maintenance, and version upgrades.

[0004] In software engineering, methods for evaluating software quality based on some evaluation index (software metrics, hereinafter simply referred to as "metrics") have been proposed.

[0005] For example, cyclomatic complexity is a metric used to measure the complexity of a program. Cyclomatic complexity quantifies the number of linearly independent paths. Metrics related to the size of software include the number of files, the number of source code fragments, and the number of functions and methods.

[0006] Furthermore, Non-Patent Document 1 proposes a metric that counts the number of identifiers to express the difficulty of understanding a program that is not well-formed, such as variations in indentation. [Prior art documents] [Non-patent literature]

[0007] [Non-Patent Document 1] Buse, RPL and WR Weimer (2010). "Learning a Metric for Code Readability." IEEE Transactions on Software Engineering 36(4): 546-558. Summary of the Invention [Problem to be solved by the invention]

[0008] Non-Patent Document 1 suggests that there is a significant correlation between code readability and software quality.

[0009] However, when a part of the code (for example, the code of a certain function) is modified, it does not suggest what kind of ripple effect the modification will have. In such cases, the difficulty of understanding the modified part needs to take into account not only the inside of the modified part, but also the relationship between the modified part and other parts. Previous metrics have not been proposed that can evaluate such a perspective.

[0010] The object of the present invention is to provide a program comprehension difficulty indicating device and method that are suitable for developing programs with excellent readability and maintainability by indicating the difficulty of program comprehension from metrics that correlate with parts of the program's source code and the entire program. [Means for solving the problem]

[0011] The configuration of the program comprehension difficulty indication device of the present invention is preferably a program comprehension difficulty indication device that indicates a program comprehension difficulty that quantitatively represents the difficulty of program comprehension in the evaluation range of the source code to be analyzed of the program, and is configured to calculate identifier metrics for each identifier within the evaluation range of identifiers that appear in the evaluation range of the source code to be analyzed, identifier metrics for each identifier outside the evaluation range of identifiers that appear in the evaluation range, and identifier metrics for each identifier that appears in the entire program, and to aggregate the identifier metrics for each identifier within the evaluation range of identifiers that appear in the evaluation range to be aggregated, the identifier metrics for each identifier outside the evaluation range of identifiers that appear in the evaluation range to be aggregated, and the identifier metrics for each identifier that appears in the entire program to be aggregated for each statistical item, and calculate the program comprehension difficulty in the evaluation range based on the values ​​aggregated for each statistical item for the identifier metrics for each identifier within the evaluation range of identifiers that appear in the evaluation range to be aggregated, the identifier metrics for each identifier outside the evaluation range of identifiers that appear in the evaluation range to be aggregated, and the identifier metrics for each identifier that appears in the entire program to be aggregated. [Effects of the Invention]

[0012] According to the present invention, it is possible to provide a program comprehension difficulty indicating device and method that are suitable for developing programs with excellent readability and maintainability by indicating the difficulty of program comprehension from metrics that correlate with parts of the program's source code and the entire program. [Brief explanation of the drawings]

[0013] [Figure 1] 1 is a block diagram showing the functional configuration of a program comprehension difficulty level indicating device according to a first embodiment. [Figure 2] 1 is a block diagram showing the hardware and software configuration of a program comprehension difficulty indicating device according to a first embodiment. [Figure 3] FIG. 10 is a diagram illustrating an example of source code to be analyzed. [Figure 4] FIG. 10 is a diagram illustrating an example of an identifier metrics item information table. [Figure 5A] FIG. 10 is a diagram illustrating an example of an evaluation range identifier metrics table according to the first embodiment. [Figure 5B] FIG. 10 is a diagram illustrating an example of an entire program identifier metrics table according to the first embodiment. [Figure 6A] FIG. 10 is a diagram illustrating an example of an evaluation range identifier metrics aggregation table. [Figure 6B] FIG. 10 is a diagram illustrating an example of an evaluation range / outside identifier metrics aggregation table. [Figure 6C] FIG. 10 is a diagram illustrating an example of an entire program identifier metrics aggregation table. [Figure 7A] FIG. 10 is a diagram illustrating an example of an evaluation range identifier metrics weight table. [Figure 7B] FIG. 10 is a diagram illustrating an example of an evaluation range / outside identifier metrics weight table. [Figure 7C] FIG. 10 is a diagram illustrating an example of an overall program identifier metrics weight table. [Figure 8] 3 is a flowchart showing the process of the program comprehension difficulty level indicating device of the first embodiment. [Figure 9] FIG. 10 is a diagram showing an example of a user interface screen using program comprehension difficulty display data. [Figure 10] FIG. 10 is a block diagram showing the functional configuration of a program comprehension difficulty level indicating device according to a second embodiment. [Figure 11] FIG. 10 is a diagram illustrating an example of a similarity evaluation table. [Figure 12A] FIG. 11 is a diagram illustrating an example of an evaluation range identifier metrics table according to the second embodiment. [Figure 12B] FIG. 11 is a diagram illustrating an example of an entire program identifier metrics table according to the second embodiment. [Figure 13] 10 is a flowchart showing the process of the program comprehension difficulty level indicating device of the second embodiment. DETAILED DESCRIPTION OF THE INVENTION

[0014] Hereinafter, each embodiment of the present invention will be described with reference to FIGS.

[0015] [Embodiment 1] Hereinafter, a first embodiment of the present invention will be described with reference to FIGS.

[0016] First, the configuration of the program comprehension difficulty indicating device of the first embodiment will be described with reference to FIGS. As shown in FIG. 1, the program comprehension difficulty indication device 100 includes the following functional units: an identifier metrics calculation unit 101, an identifier metrics aggregation unit 102, a program comprehension difficulty calculation unit 103, a program comprehension difficulty display data generation unit 104, and a memory unit 110.

[0017] The identifier metrics calculation unit 101 is a functional unit that calculates identifier metrics (details will be described later) for each identifier written in the source code of a program.

[0018] The identifier metrics counting unit 102 is a functional unit that calculates statistical data for each identifier metric designated as a counting target.

[0019] The program comprehension difficulty calculation unit 103 is a functional unit that calculates the program comprehension difficulty (details will be described later) within an evaluation range specified in the source code of a program based on statistical data for each identifier metric.

[0020] The program comprehension difficulty display data generation unit 104 is a functional unit that generates data for displaying the program comprehension difficulty of the calculated evaluation range. A specific example of a user interface using the program comprehension difficulty display data will be described later.

[0021] The storage unit 110 is a functional unit that stores data used by the program comprehension difficulty indicating device 100. The storage unit 110 stores an analysis target source code 200, an identifier metrics item information table 210, an identifier within evaluation range metrics table 220, an entire program identifier metrics table 221, an identifier within evaluation range metrics aggregation table 230, an identifier outside evaluation range metrics aggregation table 231, an entire program identifier metrics aggregation table 232, an identifier within evaluation range metrics weight table 240, an identifier outside evaluation range metrics weight table 241, an entire program identifier metrics weight table 242, and program comprehension difficulty display data 250. Details of each table will be explained later.

[0022] The program comprehension difficulty display data 250 is data for displaying the evaluation range specified in the source code and information related to the program comprehension difficulty in association with each other.

[0023] Next, the hardware and software configuration of the program comprehension difficulty indicating device will be explained using Figure 2. The hardware configuration of the program comprehension difficulty indicating device 100 is realized by a general information processing device such as a personal computer shown in FIG.

[0024] The program comprehension difficulty indication device 100 is configured in such a manner that a CPU (Central Processing Unit) 302, a main memory device 304, a network I / F (Interface) 306, a display I / F 308, an input / output I / F 310, and an auxiliary memory I / F 312 are connected by a bus.

[0025] The CPU 302 controls each part of the program comprehension difficulty indicating device 100, and loads necessary programs into the main memory 304 and executes them.

[0026] The main storage device 304 is typically configured as a volatile memory such as a RAM, and stores the programs executed by the CPU 302 and data referenced by the CPU 302.

[0027] The network I / F 306 is an interface for connecting to the network 5 .

[0028] The display I / F 308 is an interface for connecting a display device 320 such as an LCD (Liquid Crystal Display).

[0029] The input / output I / F 310 is an interface for connecting input / output devices. In the example of Fig. 2, a keyboard 330 and a mouse 332, which is a pointing device, are connected.

[0030] The auxiliary storage I / F 312 is an interface for connecting an auxiliary storage device such as an HDD (Hard Disk Drive) 350 or an SSD (Solid State Drive).

[0031] The HDD 350 has a large storage capacity and stores the programs for executing this embodiment.

[0032] The program comprehension difficulty indicating device 100 has installed therein an identifier metrics calculation program 361, an identifier metrics collection program 362, a program comprehension difficulty calculation program 363, and a program comprehension difficulty display data generation program 364.

[0033] The identifier metrics calculation program 361, the identifier metrics aggregation program 362, the program comprehension difficulty calculation program 363, and the program comprehension difficulty display data generation program 364 are programs that respectively realize the functions of the identifier metrics calculation unit 101, the identifier metrics aggregation unit 102, the program comprehension difficulty calculation unit 103, and the program comprehension difficulty display data generation unit 104.

[0034] The HDD 350 also stores the source code to be analyzed 200, an identifier metrics item information table 210, an identifier metrics table within the evaluation range 220, an entire program identifier metrics table 221, an identifier metrics aggregation table within the evaluation range 230, an identifier metrics aggregation table outside the evaluation range 231, an entire program identifier metrics aggregation table 232, an identifier metrics weight table within the evaluation range 240, an identifier metrics weight table outside the evaluation range 241, an entire program identifier metrics weight table 242, and program comprehension difficulty display data 250.

[0035] Next, a preliminary concept for explaining the program comprehension difficulty indicating device of this embodiment will be described. In this embodiment, the "program comprehension difficulty" is a quantitative evaluation of how difficult it is for software engineers to understand a specified part of source code (evaluation range). The program comprehension difficulty is defined as, for example, the larger the numerical value, the more difficult it is.

[0036] The program comprehension difficulty is calculated using "identifier metrics," which are indicators of identifiers that appear in the source code. The user designates some of the identifiers that appear in the source code as "targets for aggregation," and calculates the program comprehension difficulty for the evaluation range by taking into account the identifier metrics of the identifiers to be aggregated that appear within the evaluation range, the identifier metrics of the identifiers to be aggregated that appear within the evaluation range when they appear outside the evaluation range of the program, and the identifier metrics of the identifiers to be aggregated that appear throughout the program. The "entire program" here can be the entire function, the entire module, or the entire source code file in which the program is written.

[0037] In the example of this embodiment, the types of identifiers include, for example, "operators," "functions," "types," and "variables" in the C language, and the type to be counted is "variables."

[0038] Examples of identifier metrics are "number of occurrences per identifier," "nesting depth of occurrences per identifier," "name length per identifier," and "number of identifiers."

[0039] Next, the data used in the program comprehension difficulty indicating device of the first embodiment will be described with reference to FIGS. 3 to 7C.

[0040] The analysis target source code 200 is source code for which the program comprehension difficulty is indicated. As shown in FIG. 3, the source code in this embodiment is an int-type function called binarySearch written in C language, and the evaluation range is set to "int merge = (lrange + rrange) / 2" on the sixth line, with the entire program being the entire description of the binarySearch function. Note that binarySearch is a well-known search algorithm.

[0041] The identifier metrics item information table 210 is a table that holds a list of identifier metrics for calculating the program comprehension difficulty and information on how to measure the metrics, and as shown in Figure 4, it consists of fields for identifier metrics item name 210a, application within evaluation range 210b, application outside evaluation range 210c, and application to entire program 210d.

[0042] The identifier metrics item name 210a stores the name of the target identifier metric. In this embodiment, the following fields are stored: "Number of occurrences per identifier," "nesting depth of each identifier's occurrence," "name length per identifier," and "number of identifiers." "Number of occurrences per identifier" is a metric that indicates how many times the identifier appears in the location of interest. "nesting depth of each identifier's occurrence" is a metric that indicates the number of nestings in the location where the identifier appears (for example, the number of characters enclosed in {} in C language). "Name length per identifier" is the length of the characters that make up the target identifier. "Number of identifiers" is the number of target identifiers when identical identifiers are counted as one. The evaluation range application 210b stores a flag that indicates whether the target identifier metric is counted within the specified evaluation range. The evaluation range / external application 210c stores a flag that indicates whether target identifiers that appear within the evaluation range are counted outside the evaluation range. The entire program application 210d stores a flag that indicates whether the target identifier is counted throughout the entire program.

[0043] Specific identifier application within evaluation scope, application outside evaluation scope, and application to the entire program will be explained later.

[0044] The identifier metrics table 220 within the evaluation range is a table that holds identifier metrics for each identifier within the evaluation range, and as shown in Figure 5A, stores the following fields: identifier name 220a, type 220b, model 220c, number of occurrences per identifier 220d, nesting depth of occurrences per identifier 220e, and name length per identifier 220f.

[0045] The identifier name 220a stores the name of the identifier. The type 220b stores the type of function in the description language for that identifier (C language in this embodiment), such as "operator" or "variable." The type 220c stores the data type in the description language for that identifier. The fields of the number of occurrences per identifier 220d, nesting depth of occurrences per identifier 220e, and name length per identifier 220f store the metric values ​​corresponding to the names of the identifier metrics that are the targets of the identifier metrics item name 210a in the identifier metrics item information table 210. Note that this table does not have a field corresponding to "number of identifiers" because the number of identifiers is not a metric that is converted for each identifier.

[0046] In the source code 200 to be analyzed shown in Figure 3, when the evaluation range is the sixth line, the identifiers that appear in the evaluation range are " / ", "+", "=", "int", "lrange", "mrange", and "rrange", as shown in Figure 5A.

[0047] Here, when the objects to be counted are limited to those whose identifier type is "variable," the identifiers shown in record group R01 (records 5 to 7) are used to calculate the program comprehension difficulty. Note that in this embodiment, the objects to be counted are selected by the type of identifier, but they may also be selected by the type of identifier, or by a combination of the type and type of identifier.

[0048] For example, for an identifier whose identifier name 220a is "lrange", the number of occurrences per identifier 220d is "1", the nesting depth of occurrences per identifier 220e is "2", and the name length per identifier 220f is "6".

[0049] The program-wide identifier metrics table 221 is a table that holds identifier metrics for each identifier in the entire program, and as shown in Figure 5B, stores the following fields: identifier name 221a, type 221b, model 221c, number of occurrences per identifier 221d, nesting depth of occurrence per identifier 221e, and name length per identifier 221f.

[0050] Each field is similar to the within-evaluation-range identifier metrics table 220 in FIG. 5A.

[0051] When the objects to be aggregated are limited to those whose identifier type is "variable," the identifiers shown in record group R02 (records 17 to 21) are used to calculate the program comprehension difficulty of the entire program, and the identifiers shown in record group R03 (records 19 to 21) are used to calculate the program comprehension difficulty within and outside the evaluation range of identifiers within the evaluation range (i.e., "lrange," "mrange," and "rrange").

[0052] The identifier metrics aggregation table 230 within the evaluation range is a table that holds aggregated values ​​of identifier metrics within the evaluation range of the source code 200 to be analyzed, and as shown in Figure 6A, stores the following fields: identifier metrics item name 230a, average 230b, maximum 230c, minimum 230d, variance 230e, median 230f, and total 230g.

[0053] The identifier metric item name 230a stores the name of the identifier metric. The average 230b stores the average value of the identifier metric within the evaluation range of the identifier to be aggregated (the values ​​of record group R01 in the evaluation range identifier metrics table 220 in Figure 5A are referenced; the same applies below). The maximum 230c stores the maximum value of the identifier metric within the evaluation range of the identifier to be aggregated. The minimum 230d stores the minimum value of the identifier metric within the evaluation range of the identifier to be aggregated. The variance 230e stores the variance of the values ​​of the identifier metric within the evaluation range of the identifier to be aggregated. The median 230f stores the median value of the identifier metric within the evaluation range of the identifier to be aggregated. The total 230g stores the total value of the identifier metric within the evaluation range of the records to be aggregated. However, for records whose identifier metric is "number of identifiers," the number of identifiers within the evaluation range is directly stored.

[0054] For example, when the identifier metrics item name 230a is “Number of occurrences per evaluation range,” the values ​​of the average 230b, maximum 230c, minimum 230d, variance 230e, median 230f, and total 230g are “1,” “1,” “1,” “0,” “1,” and “3,” respectively.

[0055] The identifier metrics aggregation table 231 within and outside the evaluation range is a table that holds aggregated values ​​of identifier metrics outside the evaluation range of identifiers that appear in the evaluation range of the source code 200 to be analyzed, and as shown in Figure 6B, it stores the following fields: identifier metrics item name 231a, average 231b, maximum 231c, minimum 231d, variance 231e, median 231f, and total 231g.

[0056] The meaning of each field is the same as that of the within-evaluation-range identifier metrics aggregation table 230 shown in FIG. 6A.

[0057] However, it should be noted that the only meaningful identifier metrics here are the "number of occurrences per identifier" and the "nesting depth of the occurrences per identifier."

[0058] The entire program identifier metrics aggregation table 232 is a table that holds the aggregated values ​​of the identifier metrics to be aggregated that appear throughout the entire program of the source code 200 to be analyzed, and as shown in Figure 6C, it stores the following fields: identifier metrics item name 231a, average 231b, maximum 231c, minimum 231d, variance 231e, median 231f, and total 231g.

[0059] In this table, the meaning of each field is the same as that of the within-evaluation-range identifier metrics aggregation table 230 shown in FIG. 6A.

[0060] The within evaluation range identifier metrics weight table 240 is a table that holds weighting coefficients corresponding to the within evaluation range identifier metrics aggregation table 230. As shown in Fig. 7A, the identifier metrics item name 240a of each record in the within evaluation range identifier metrics weight table 240 has the same value as the identifier metrics item name 230a of each record in the within evaluation range identifier metrics aggregation table 230, and the average 240b, maximum 240c, minimum 240d, variance 240e, median 240f, and total 240g of the within evaluation range identifier metrics weight table 240 take values ​​that correspond to the average 230b, maximum 230c, minimum 230d, variance 230e, median 230f, and total 230g fields of the within evaluation range identifier metrics aggregation table 230, respectively.

[0061] The evaluation range / outside identifier metrics weight table 241 is a table that holds weighting coefficients corresponding to the evaluation range / outside identifier metrics aggregation table 231. As shown in Fig. 7B, the identifier metrics item name 241a of each record in the evaluation range / outside identifier metrics weight table 241 has the same value as the identifier metrics item name 231a of each record in the evaluation range / outside identifier metrics aggregation table 231, and the average 240b, maximum 240c, minimum 240d, variance 240e, median 240f, and total 240g in the evaluation range identifier metrics weight table 240 take values ​​that correspond to the average 231b, maximum 231c, minimum 231d, variance 231e, median 231f, and total 231g fields in the evaluation range / outside identifier metrics aggregation table 231, respectively.

[0062] The overall program identifier metrics weight table 242 is a table that holds weighting coefficients corresponding to the overall program identifier metrics aggregation table 232. As shown in Fig. 7C, the identifier metrics item name 242a of each record in the overall program identifier metrics weight table 242 has the same value as the identifier metrics item name 232a of each record in the overall program identifier metrics aggregation table 232, and the average 242b, maximum 242c, minimum 242d, variance 242e, median 242f, and total 242g of the overall program identifier metrics weight table 242 take values ​​corresponding to the average 232b, maximum 232c, minimum 232d, variance 232e, median 232f, and total 232g fields of the overall program identifier metrics aggregation table 232.

[0063] However, since the average 230b, maximum 230c, minimum 230d, variance 230e, and median 230f for records in the within-evaluation-range identifier metrics aggregation table 230 where the identifier metric item name is "number of identifications" are NULL values, the average 240b, maximum 240c, minimum 240d, variance 240e, and median 240f of the corresponding within-evaluation-range identifier metric weight table 240 are padded with "0".

[0064] Similarly, for records in the program-wide identifier metrics aggregation table 232 where the identifier metric item name is "Number of Identifications," the average 232b, maximum 232c, minimum 232d, variance 232e, and median 232f are also NULL values, so the corresponding average 242b, maximum 242c, minimum 242d, variance 242e, and median 242f in the program-wide identifier metric weight table 242 are padded with "0."

[0065] The specific average, maximum, minimum, variance, median, and total weight values ​​of the evaluation range identifier metric weight table 240, the evaluation range outside identifier metric weight table 241, and the program-wide identifier metric weight table 242 can be determined, for example, by learning using supervised data.

[0066] In the example of embodiment 1, the model uses only the number of occurrences of each identifier and the nesting depth of the occurrences of each identifier as identifier metrics related to the difficulty of program comprehension, and the values ​​place emphasis on the identifier metrics of identifiers that appear within the evaluation range and the identifier metrics of identifiers that appear within the evaluation range but outside the evaluation range.

[0067] In addition, the algorithm for calculating the difficulty of program comprehension within the evaluation range using the evaluation range identifier metrics aggregation table 230, evaluation range / outside evaluation range identifier metrics aggregation table 231, entire program identifier metrics aggregation table 232, evaluation range identifier metrics weight table 240, evaluation range / outside evaluation range identifier metrics weight table 241, and entire program identifier metrics weight table 242 will be explained later.

[0068] Next, the process of the program comprehension difficulty level indicating device of the first embodiment will be described with reference to FIG. First, the program comprehension difficulty indicating device 100 reads the source code 200 to be analyzed (S100).

[0069] Next, the program comprehension difficulty level indicating device 100 reads the values ​​of the identifier metrics item information table 210 shown in FIG. 4 (S101).

[0070] Next, the program comprehension difficulty indicating device 100 identifies the evaluation range of the source code 200 to be analyzed for which the program comprehension difficulty is to be calculated and the identifier of the target of aggregation for that evaluation range (S102). The evaluation range and the identifier of the target of aggregation may be input by the user using an input tool, or may be identified based on the information read from a configuration file. In this embodiment, the evaluation range is the sixth line of the source code 200 to be analyzed in FIG. 3, and the identifier of the target of aggregation is an identifier whose type is "variable."

[0071] Next, the program comprehension difficulty indicating device 100 calculates identifier metrics for each identifier (S103), and sets values ​​in the evaluation range identifier metrics table 220 shown in FIG. 5A and the entire program identifier metrics table 221 shown in FIG. 5B.

[0072] Next, the program comprehension difficulty indication device 100 refers to the identifier metrics table 220 within the evaluation range and the entire program identifier metrics table 221, and aggregates the identifier metrics for each identifier for the identifiers to be aggregated (S104), and sets the aggregated results of the identifier metrics for the identifiers to be aggregated within the evaluation range in the identifier metrics aggregation table 230 within the evaluation range shown in Figure 6A, the aggregated results of the identifier metrics for the identifiers to be aggregated within the evaluation range but outside the evaluation range in the identifier metrics aggregation table 231 outside the evaluation range shown in Figure 6B, and the aggregated results of the identifier metrics for the identifiers for the entire program of the source code 200 to be analyzed in the entire program identifier metrics aggregation table 232 shown in Figure 6C.

[0073] Next, the program comprehension difficulty indication device 100 reads the evaluation range identifier metrics weight table 240 shown in Figure 7A, the evaluation range outside identifier metrics weight table 241 shown in Figure 7B, and the entire program identifier metrics weight table 242 shown in Figure 7C (simply referred to as "weight tables" in the figure), and refers to these tables and the values ​​of the evaluation range identifier metrics aggregation table 230, the evaluation range outside identifier metrics aggregation table 231, and the entire program identifier metrics aggregation table 232, and calculates the program comprehension difficulty of the evaluation range based on the following (Equation 1) (S106).

[0074]

number

[0075] Here, Σ1 is the value of the j column (j=1 to 6 for the average 230a to the total 230g) of the i row (i-th record) of the evaluation range identifier metrics aggregation table 230, ij The value of the jth column (j=1 to 6 for the average 240a to the total 240g) of the ith row (ith record) of the evaluation range identifier metric weight table 240 is expressed as w ij Σ2 means to take the sum for all combinations of (i, j), and the value of the j column (j=1 to 6 for the average 231a to the total 231g) of the i row (i-th record) of the evaluation range / outside identifier metrics aggregation table 231 is calculated as m ij The value of the j column (where j=1 to 6 for the average 241a to the total 241g) of the i row (i-th record) of the evaluation range / outside identifier metric weight table 241 is expressed as w ij Σ3 means to take the sum of all combinations of (i, j), and the value of the j column (j=1 to 6 for the average 232a to the total 232g) of the i row (i-th record) of the program-wide identifier metrics aggregation table 232 is calculated as m ij The value of the jth column (j=1 to 6 for the average 242a to the total 242g) in the i-th row (i-th record) of the program-wide identifier metrics weight table 242 is expressed as wij This means taking the sum of all combinations of (i, j).

[0076] Next, the program understanding difficulty indicating device 100 generates the program understanding difficulty display data 250 based on the calculated program understanding difficulty of the evaluation range (S107).

[0077] The program comprehension difficulty display data 250 is data that associates, for example, the location of the evaluation range with the program comprehension difficulty and the program comprehension class (details will be described later) estimated from the program comprehension difficulty.

[0078] Next, a user interface using the program comprehension difficulty level display data will be described with reference to FIG. The program comprehension difficulty can be incorporated into, for example, a source code editor tool or a maintenance tool, and by indicating the difficulty of program comprehension, it can alert developers and debuggers and improve the efficiency of program development.

[0079] As shown in FIG. 9, on a source code display screen 500 of the source code editor, a program comprehension difficulty level 501 and a program comprehension class 502 are displayed on the right side of each source code.

[0080] Here, the larger the value of the program comprehension difficulty, the more difficult it is to understand the program, and the smaller the value, the easier it is to understand the program. For example, the program comprehension class 502 is displayed as follows: 0 or more and less than 9 is [C], 9 or more and less than 10 is [B], and 10 or more is [A]. Note that in the example of Fig. 9, the display is from [A] to [C], but the relevant parts may be displayed in different colors to make the classification easier to understand visually.

[0081] As described above, by introducing the program comprehension difficulty level using the program comprehension difficulty indicating device of this embodiment, the following advantages are obtained in software development.

[0082] During the program design stage, when a search query is entered to investigate the extent of the impact on source code, in order to encourage investigation of difficult-to-understand parts, the degree of match of the query (= number of matching characters / search target sentence) is weighted by the difficulty of understanding, and files that exceed a threshold are displayed as files requiring investigation.

[0083] In addition, to assist in investigating difficult parts of a program that are difficult to understand, the system can highlight the difficult parts, manage people who have viewed the difficult parts to make it easier to contact them, and present documents that people who have viewed the difficult parts have also viewed.

[0084] Furthermore, as shown in Figure 9, by outputting the source code to a code editor during the coding stage, alerts are displayed for parts that are difficult to read and likely to reduce maintainability, prompting corrections and improving the maintainability of the program.

[0085] In the source code debugging stage, the program comprehension difficulty of this embodiment makes it possible to display as possible causes of bugs points in related modules that are likely to be misunderstood.

[0086] Furthermore, in the maintenance stage, in order to improve the maintainability of a program under development using the program comprehension difficulty of this embodiment, the program being programmed can be analyzed, and difficult-to-read parts and parts that may lead to bugs can be pinpointed and identified in real time at units finer than functions, and the relevant parts can be highlighted and notified to the developer to urge them to make corrections or checks.

[0087] Furthermore, in reviewing source code, the program comprehension difficulty of this embodiment makes it easier for reviewers to pinpoint parts that are difficult to read and need to be corrected, thereby reducing review time.

[0088] Furthermore, in the refactoring stage, the program comprehension difficulty of this embodiment makes it easier to automatically determine whether or not a refactoring tool should be applied, so that parts that are difficult to understand can be presented, and the refactoring method for parts that are difficult to understand can be managed, making it easier to change the program to one that is easier to understand.

[0089] Furthermore, in the course of development work, the program comprehension difficulty level of this embodiment can encourage the developer to sort out parts of the program that are difficult to understand.

[0090] As described above, according to the program comprehension difficulty indication device of this embodiment, it is possible to indicate the program comprehension difficulty from metrics that correlate with a portion of the program's source code and the entire program, thereby developing a program that is easy to read and maintain.

[0091] [Embodiment 2] Hereinafter, a second embodiment of the present invention will be described with reference to FIGS.

[0092] In embodiment 1, we described a program comprehension difficulty indication device that indicates the difficulty of program comprehension based on identifier metrics of identifiers that appear within the evaluation range, identifier metrics of identifiers that appear within the evaluation range but outside the evaluation range, and identifier metrics of identifiers that appear throughout the entire program.

[0093] However, when identifiers with similar spellings are written, the source code may become difficult to read. For example, the "mrange," "lrange," and "rrange" that appear in the evaluation ranges in the first embodiment have similar spellings, which may cause confusion for program developers.

[0094] In this embodiment, the concept of similarity of identifier names is also introduced, and identifier names with high similarity are aggregated as new identifier names to be used to calculate identifier metrics, thereby calculating a more precise program comprehension difficulty.

[0095] The following description will focus on the differences from the first embodiment. The analysis source code taken as an example is the same as in the first embodiment, and is shown in FIG.

[0096] First, the configuration of the program comprehension difficulty level indicating device of the second embodiment will be described with reference to FIG.

[0097] The program comprehension difficulty indicating device 100 of this embodiment is configured by adding an identifier similarity calculation unit 120 and an aggregate identifier name generation unit 121 to the program comprehension difficulty indicating device 100 of the first embodiment shown in FIG.

[0098] The identifier similarity calculation unit 120 is a functional unit that calculates the similarity of identifiers (details will be described later). The aggregation identifier name generation unit 121 is a functional unit that generates an aggregation identifier name (details will be described later) from two identifiers.

[0099] Furthermore, the storage unit 110 further includes a similarity evaluation table 260 in addition to the data and tables of the storage unit 110 of the program comprehension difficulty indicating device 100 of embodiment 1. The similarity evaluation table 260 will be described in detail later.

[0100] Next, the data used in the program comprehension difficulty indicating device of the second embodiment will be described with reference to FIGS. 11 to 12B.

[0101] The similarity evaluation table 260 is a table that stores information about the similarity of identifier names in source code, and as shown in Figure 11, it consists of fields for comparison source identifier name 260a, comparison target identifier name 260b, longest common substring 260c, similarity 260d, and aggregation 260e.

[0102] The comparison source identifier name 260a and the comparison target identifier name 260b each store the identifier name of one of the identifiers appearing in the analysis target source code 200. The longest common substring 260c stores the longest character string that is commonly contained in the identifier names stored in the comparison source identifier name 260a and the comparison target identifier name 260b. The similarity 260d stores the similarity of the identifier names stored in the comparison source identifier name 260a and the comparison target identifier name 260b. The similarity of the identifier names is calculated, for example, by the following (Equation 2).

[0103]

number

[0104] The aggregation 260e stores a flag indicating whether the identifier names stored in the comparison source identifier name 260a and comparison target identifier name 260b are aggregated to form a single aggregate identifier name. For example, if their similarity is equal to or greater than a threshold value of 0.8, they are aggregated to form an aggregate identifier name. The aggregate identifier name is their longest common substring.

[0105] The evaluation range identifier metrics table 220 of this embodiment has the same structure as the evaluation range identifier metrics table 220 shown in Figure 5A, but as shown in Figure 12A, a record R10 (record 8) with a new identifier name 220a ``range'' has been added.

[0106] This means that from records 8 to 9 (value of similarity 260d≧0.8) in the similarity evaluation table 260 shown in FIG. 11, the aggregate identifier name “range” was generated from the character string of the longest common substring 260c.

[0107] The value of the number of occurrences per identifier 220d of a record of an aggregate identifier name is the sum of the number of occurrences per identifier 220d of the records having the original identifier name from which the aggregate identifier name was taken. The value of the nesting depth 220e of the occurrences per identifier of a record of an aggregate identifier name is the maximum value of the nesting depth 220e of the occurrences per identifier of the records having the original identifier name from which the aggregate identifier name was taken. The value of the name length per identifier 220f of a record of an aggregate identifier name is the character string length of the aggregate identifier name (longest common substring) itself.

[0108] The program-wide identifier metrics table 221 of this embodiment has the same structure as the program-wide identifier metrics table 221 shown in Figure 5B, but as shown in Figure 12B, a record R11 (record 22) having a new identifier name 220a "range" has been added.

[0109] The meanings of the values ​​of the number of occurrences per identifier 221d, the nesting depth of occurrences per identifier 221e, and the name length per identifier 221f are the same as those explained in the within-evaluation-range identifier metrics table 220.

[0110] Next, the process of the program comprehension difficulty level indicating device of the second embodiment will be described with reference to FIG. The process of the program comprehension difficulty indicating device of the second embodiment is almost the same as that shown in the flowchart of the first embodiment shown in FIG. 8, except that steps S200 and S201 are added between steps S102 and S103.

[0111] After executing S102, the program comprehension difficulty indicating device 100 analyzes the identifiers (type: "variable") to be counted in the source code to be analyzed 200, and creates the similarity evaluation table 260 (S200).

[0112] As already explained, the similarity between the comparison source identifier name and the comparison target identifier name is calculated using (Equation 2).

[0113] Then, the program comprehension difficulty indicating device 100 refers to the similarity evaluation table 260 and generates an aggregate identifier name from the values ​​of the comparison source identifier name 260a and the comparison target identifier name 260b of records that are equal to or greater than a certain threshold value (0.8) (S201).

[0114] That is, in the example of this embodiment, the aggregation identifier name is generated from records 8 to 9 of the similarity evaluation table 260.

[0115] In S103, values ​​are set in the evaluation range identifier metrics table 220 shown in FIG. 12A and the entire program identifier metrics table 221 shown in FIG. 12B, which contain the record of this aggregate identifier name.

[0116] As explained above, according to this embodiment, based on a program comprehension difficulty indication device similar to that of embodiment 1, the concept of similarity of identifier names is also introduced, and identifiers with high similarity are aggregated as identifier names, and are used to calculate new identifier metrics, thereby making it possible to calculate a more precise program comprehension difficulty. [Explanation of symbols]

[0117] 100... program comprehension difficulty indication device, 101... identifier metrics calculation unit, 102... identifier metrics aggregation unit, 103... program comprehension difficulty calculation unit, 104... program comprehension difficulty display data generation unit, 120... identifier similarity calculation unit, 121... aggregated identifier name generation unit, 110... storage unit, 200...Source code to be analyzed, 210...Identifier metrics item information table, 220...Identifier metrics table within evaluation range, 221...Whole program identifier metrics table, 230...Identifier metrics aggregation table within evaluation range, 231...Identifier metrics aggregation table outside evaluation range, 232...Whole program identifier metrics aggregation table, 240...Identifier metrics weight table within evaluation range, 241...Identifier metrics weight table outside evaluation range, 242...Whole program identifier metrics weight table, 250...Program comprehension difficulty display data, 260...Similarity evaluation table

Claims

1. A program comprehension difficulty indicating device that indicates a program comprehension difficulty that quantitatively represents the difficulty of program comprehension regarding an evaluation range of a source code to be analyzed for a program, determining identifier metrics for each identifier within the evaluation range of the identifiers appearing in the evaluation range of the source code to be analyzed, identifier metrics for each identifier outside the evaluation range of the identifiers appearing in the evaluation range, and identifier metrics for each identifier appearing in the entire program; The identifier metrics for each identifier within the evaluation range of the identifiers that appear in the evaluation range to be aggregated, the identifier metrics for each identifier outside the evaluation range of the identifiers that appear in the evaluation range to be aggregated, and the identifier metrics for each identifier that appears in the entire program to be aggregated are aggregated for each statistical item, A program comprehension difficulty indication device characterized by calculating the program comprehension difficulty within the evaluation range based on values ​​aggregated for each statistical item for identifier metrics for each identifier within the evaluation range of identifiers that appear in the evaluation range to be aggregated, identifier metrics for each identifier outside the evaluation range of identifiers that appear in the evaluation range to be aggregated, and identifier metrics for each identifier of identifiers that appear in the entire program to be aggregated.

2. 2. The program comprehension difficulty indicating device according to claim 1, wherein said identifier metrics are the number of occurrences of each identifier, the nesting depth of each identifier's occurrence, and the name length of each identifier.

3. The program comprehension difficulty indication device according to claim 1, characterized in that the statistical items are the mean value, maximum value, minimum value, variance, median, or the sum of the identifiers of the objects to be counted that appear within the evaluation range, the sum of the identifiers of the objects to be counted that appear outside the evaluation range, or the sum of the identifiers of the objects to be counted that appear in the entire program.

4. A weighting coefficient is stored for each of the identifier metrics for each identifier within the evaluation range of the identifiers that appear in the evaluation range to be aggregated, the identifier metrics for each identifier outside the evaluation range of the identifiers that appear in the evaluation range to be aggregated, and the identifier metrics for each identifier of the identifiers that appear in the entire program to be aggregated, and the weighting coefficient is stored for each of the values ​​aggregated for each statistical item. The program comprehension difficulty indication device according to claim 1, characterized in that the program comprehension difficulty is calculated by a linear sum obtained by multiplying the values ​​aggregated for each statistical item by a weighting coefficient for each aggregated value for each of the identifier metrics for each identifier within the evaluation range of identifiers that appear in the evaluation range to be aggregated, the identifier metrics for each identifier outside the evaluation range of identifiers that appear in the evaluation range to be aggregated, and the identifier metrics for each identifier that appear in the entire program to be aggregated.

5. A program comprehension difficulty indicating method by a program comprehension difficulty indicating device that indicates a program comprehension difficulty that quantitatively represents the difficulty of program comprehension regarding an evaluation range of a source code to be analyzed, comprising: a step in which the program comprehension difficulty indicating device obtains identifier metrics for each identifier within the evaluation range of identifiers appearing in the evaluation range of the source code to be analyzed, identifier metrics for each identifier outside the evaluation range of identifiers appearing in the evaluation range, and identifier metrics for each identifier appearing in the entire program; a step in which the program comprehension difficulty indicating device aggregates, for each statistical item, identifier metrics for each identifier within the evaluation range of identifiers that appear in the evaluation range to be aggregated, identifier metrics for each identifier outside the evaluation range of identifiers that appear in the evaluation range to be aggregated, and identifier metrics for each identifier of identifiers that appear in the entire program to be aggregated; a step in which the program comprehension difficulty indicating device calculates the program comprehension difficulty in the evaluation range based on the values ​​aggregated for each statistical item for identifier metrics for each identifier within the evaluation range of identifiers that appear in the evaluation range to be aggregated, identifier metrics for each identifier outside the evaluation range of identifiers that appear in the evaluation range to be aggregated, and identifier metrics for each identifier of identifiers that appear in the entire program to be aggregated; A program comprehension difficulty indication method characterized in that the program comprehension difficulty indication device has a step of generating display data that displays the program comprehension difficulty within the calculated evaluation range.

Citation Information

Patent Citations

  • Complexity calculation device, complexity calculation method, and complexity calculation program

    JP2014032466A

  • Information processing apparatus and information processing method

    JP2023181593A

  • Metering Based On Application Code Complexity

    US20200234346A1