CN110580218A - software code complexity detection method and device and electronic equipment - Google Patents

software code complexity detection method and device and electronic equipment Download PDF

Info

Publication number
CN110580218A
CN110580218A CN201810590045.7A CN201810590045A CN110580218A CN 110580218 A CN110580218 A CN 110580218A CN 201810590045 A CN201810590045 A CN 201810590045A CN 110580218 A CN110580218 A CN 110580218A
Authority
CN
China
Prior art keywords
aggregation
code
complexity
code complexity
scores
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810590045.7A
Other languages
Chinese (zh)
Inventor
邓水光
傅珉
智晨
陈曦
尹建伟
李元平
朱海
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang University ZJU
Original Assignee
Zhejiang University ZJU
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang University ZJU filed Critical Zhejiang University ZJU
Priority to CN201810590045.7A priority Critical patent/CN110580218A/en
Publication of CN110580218A publication Critical patent/CN110580218A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/441Register allocation; Assignment of physical memory space to logical memory space

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the invention provides a method and a device for detecting software code complexity and electronic equipment, wherein the method comprises the following steps: acquiring code complexity indexes of a plurality of code segments of software to be evaluated; carrying out longitudinal aggregation on the code complexity indexes of the code segments step by step to obtain a first aggregation score; and transversely aggregating the first aggregation scores to obtain second aggregation scores, and outputting the second aggregation scores as the code complexity. In addition, by backtracking the complexity detection process of the step-by-step aggregation, the method and the device can facilitate developers to locate code segments with problems in the code complexity aspect.

Description

software code complexity detection method and device and electronic equipment
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for detecting software code complexity, and an electronic device.
background
with the development of computer science and technology, the application range and scale of software are continuously enlarged. At present, under the large background that software application scenes are wider, software quality becomes a more concerned problem for professional technicians. In software quality assessment, code quality is an important part of software quality, which largely determines software quality. Traditional software metrics are mainly based on structured and modular programming ideas, and main analysis objects include code scale, program control flow, implementation complexity and the like. The complexity of the code is just one of the important factors influencing the failure rate and maintainability of the code, and is more important especially in large-scale codes. For the detection and evaluation of the code complexity, only some complexity indexes aiming at specific code segments are proposed at the present stage, but a complete detection and evaluation mechanism aiming at the complexity of the whole software is not formed yet.
disclosure of Invention
The embodiment of the invention provides a method and a device for detecting software code complexity and electronic equipment, so as to realize comprehensive and deep detection and evaluation of the software code complexity.
The embodiment of the invention provides a method for detecting software code complexity, which comprises the following steps:
Acquiring code complexity indexes of a plurality of code segments of software to be evaluated;
carrying out longitudinal aggregation on the code complexity indexes of the code segments step by step to obtain a first aggregation score;
And transversely aggregating the first aggregation scores to obtain second aggregation scores, and outputting the second aggregation scores as the code complexity.
The embodiment of the invention also provides a device for detecting the complexity of the software code, which comprises:
The code complexity index acquisition module is used for acquiring a code complexity index of a code segment of the software to be evaluated;
The longitudinal aggregation module is used for carrying out longitudinal aggregation on the code complexity indexes of the code segments step by step to obtain a first aggregation score;
and the transverse aggregation module is used for transversely aggregating the first aggregation scores to obtain second aggregation scores, and outputting the second aggregation scores as the code complexity.
An embodiment of the present invention further provides an electronic device, including:
A memory for storing a program;
A processor, coupled to the memory, for executing the program for:
Acquiring code complexity indexes of a plurality of code segments of software to be evaluated;
carrying out longitudinal aggregation on the code complexity indexes of the code segments step by step to obtain a first aggregation score;
and transversely aggregating the first aggregation scores to obtain second aggregation scores, and outputting the second aggregation scores as the code complexity.
The embodiment of the invention provides a method and a device for detecting software code complexity and electronic equipment, wherein the method and the device adopt a step-by-step longitudinal aggregation mode to detect and evaluate the code complexity of software to be evaluated, and the code complexity indexes of a plurality of code segments at the bottommost layer are aggregated step by step upwards, so that the code complexity condition of each level can be fully collected, and further, a comprehensive and deep complexity detection result is formed.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
drawings
FIG. 1 is a logic diagram illustrating the detection of software code complexity according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a method for detecting software code complexity according to a first embodiment of the present invention;
FIG. 3 is a flowchart illustrating a method for detecting software code complexity according to a second embodiment of the present invention;
FIG. 4 is a schematic structural diagram of an apparatus for detecting software code complexity according to an embodiment of the present invention;
Fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
Description of terms:
the code complexity, namely the complexity of the code in the characterization software, is an important standard for evaluating the software quality, and is also one of important factors influencing the code failure rate and the code maintainability in the software.
Code complexity index, i.e., a measure of code complexity. In the development process of software measurement, new indexes related to code complexity are proposed continuously, such as circle complexity, number of weighting methods in classes, and the like.
The Method type index refers to a code complexity index for measuring the dimension of a Method function in a code, for example, the round complexity, the number of effective rows of methods, the number of parameters of methods, and the like.
The Type indicator refers to a code complexity indicator for measuring the dimension of a data structure in the source code, where the data structure includes a class structure, a data Type structure, and the like defined in the program, for example, the number of member methods, the number of member variables, the number of weighting methods, and the like.
long-tailed distribution, refers to a distribution of individuals (data), wherein fewer individuals (data) correspond to higher values, and individuals (data) with lower values account for the vast majority of the population.
In addition, in order to facilitate the explanation of the technical solution of the embodiment of the present invention, the following names are defined in the description process:
A code segment refers to a set of code in software that includes method functions and/or classes of data structures.
And the first aggregation score is the code complexity score at the highest level after the code complexity indexes of the code segments of the software to be evaluated are longitudinally aggregated step by step. For example, if the code segments of the software to be evaluated are longitudinally aggregated step by step in the class layer, the module layer, the file layer and the project layer, the code complexity score in the project layer is the first aggregation score.
And the second aggregation score refers to the code complexity score after the code complexity indexes of the code segments of the software to be evaluated are aggregated transversely, namely the final code complexity detection result of the software to be evaluated.
The weakly term intensive aggregation function refers to an aggregation function capable of giving a larger weight to a smaller value without changing the value range.
The technical principle of the embodiment of the invention is as follows: the code complexity of the software to be evaluated is detected and evaluated in a step-by-step longitudinal aggregation mode, and the code complexity indexes of a plurality of code segments at the bottommost layer are aggregated upwards step by step, so that the code complexity conditions of all dimensions and all levels can be fully collected, and a comprehensive and deep complexity detection result is formed. In addition, by tracing back the complexity detection process of gradual aggregation, developers can be facilitated to locate code segments with problems in terms of code complexity.
as shown in fig. 1, which is a logic schematic diagram of software code complexity detection according to an embodiment of the present invention, as shown in the drawing, in this embodiment, the software code complexity detection mainly includes three steps of obtaining a code complexity index, hierarchical vertical aggregation step by step, and horizontal aggregation, which are detailed as follows:
firstly, in order to detect the software code complexity, the code complexity index of a code segment of software to be evaluated needs to be obtained, and in order to achieve the purpose of detecting the software code complexity in an all-around and multi-dimensional manner, the code complexity indexes of multiple dimensions can be collected, and the code complexity indexes mainly comprise a Method Type index and a Type index. The Method type indexes include, but are not limited to, the Circle Complexity (CC) of a code segment of software to be evaluated, the number of active Lines (LOCM) of a Method, the number of parameters (NOP) of a Method and the maximum nesting level number (MND) of a Method; the Type indicators include, but are not limited to, the number of member methods (NOM), the number of member variables (NOF), and the number of Weighted Methods (WMC) of the code snippet of the software to be evaluated.
In an actual application scenario, the code complexity index can be obtained by collecting original measurement data of a code segment and mapping the original measurement data according to a preset threshold interval. Specifically, an index calculator can be called to collect original measurement data of code complexity indexes of multiple dimensions, different threshold intervals are preset for different types of code complexity indexes, and the original measurement data are mapped into discrete values in a preset range according to different threshold intervals where the original measurement data are located, so that the code complexity indexes are obtained.
it should be noted that the values of the code complexity indexes are numerical data. In addition, based on knowledge and experience in the field, the original measurement data of the code complexity index always presents long tail distribution, and in order to reduce errors of the code complexity index caused by the long tail distribution effect and enable the code complexity index to be more consistent with a real scene, the preset percentile of the threshold interval of the original measurement data can be adjusted, for example, if the preset percentile of a certain threshold interval corresponding to the original measurement data is 90%, a certain point in the threshold interval is taken as a percentile, so that 90% of the original measurement data in the threshold interval are smaller than the value of the original measurement data corresponding to the percentile, and the method is favorable for reducing errors of the detection result of the software code complexity caused by the long tail distribution effect.
and then, based on the code complexity indexes obtained in the steps, longitudinally aggregating the values of each type of code complexity indexes according to the hierarchical sequence of any plurality of layers in the class layer, the file layer, the module layer and the project layer. As shown in fig. 1, for the obtained Method Type index and Type index, firstly, aggregating the obtained Method Type index and Type index at a class level according to an aggregation function, so as to obtain an aggregation score at a file level; then, aggregating the aggregation scores of the file levels at the file levels according to an aggregation function to obtain the aggregation scores of the module levels; and finally, aggregating the aggregation scores of the module levels at the module levels according to an aggregation function, so as to obtain the aggregation score of the item levels, namely the first aggregation score.
It should be noted that the Method Type indicator and the Type indicator are two parallel Type indicators, but in the process of acquiring raw metric data, the Type indicator may need to use the raw metric data of the Method Type indicator or a code complexity indicator. For example, the weighted Method number (WMC) indicator in the Type indicator is calculated as the sum of the round-robin complexity (CC) of the code methods in the class, and the round-robin complexity (CC) is one of the Method Type indicators.
In addition, the aggregation function may employ a weak term intensive aggregation function, such as an aggregation functionWherein f (x) is the overall aggregation score of the hierarchy to which the vertical aggregation is directed, xian aggregation score or code complexity index for each aggregated unit of the hierarchy for which the vertical aggregation is directed. The aggregation score corresponding to the problem code is usually smaller, while the weak term intensive function can give smaller value and larger weight without changing the value range, so that the problem code can be highlighted through the weak term intensive aggregation functionThe purpose is. Moreover, when the software code complexity detection result is low in score, the program layer, the module layer, the file layer and the class layer can be traced back layer by layer from top to bottom in sequence, and therefore developers can be helped to locate code segments with problems in the code complexity aspect.
It should be noted that, based on the code complexity index and the aggregation scores of each level, long-tailed distribution may be presented, in order to reduce an error of a software code complexity detection result, so that the software code complexity detection result more conforms to a real scene, the aggregation scores corresponding to each level may be adjusted, and a specific adjustment method may adopt the method for determining the percentile according to the reference data, which is not described herein again.
finally, based on the first aggregation scores obtained in the above steps, a second aggregation score, that is, the code complexity output of the code segments of the software to be evaluated, can be obtained by performing horizontal aggregation, for example, calculating an average value of the first aggregation scores of the plurality of code segments.
it should be noted that, the more complex the code in the code segment of the software to be evaluated, for example, the more the number of code lines or the more the number of methods, the higher the code complexity index is, and the lower the first aggregation score is, and correspondingly, the lower the second aggregation score is, that is, the lower the code complexity output value of the code segment of the software to be evaluated is. As can be seen, the more complex the code in a code segment, the lower the score, and often the problem code exists in the code segment with the lower score.
the technical solution of the present application is further illustrated by the following examples.
Example one
Based on the above technical idea of detecting software code complexity, as shown in fig. 2, a flowchart of a method for detecting software code complexity according to a first embodiment of the present invention is shown, where an execution main body of the method is a device for detecting software code complexity, and the method includes:
s210, code complexity indexes of a plurality of code segments of the software to be evaluated are obtained.
As described above, the code complexity index may be obtained by collecting raw metric data of a code segment and mapping the raw metric data according to a preset threshold interval.
in an actual application scene, the original measurement data of the code complexity indexes of multiple dimensions can be collected by calling the index calculator, and different threshold intervals { t ] are preset for different types of code complexity indexes1,t2...tnaccording to the threshold interval { t ] of the original measurement data1,t2...tnAnd (4) mapping the original measurement data into integer discrete values in the range of 0 to n, and taking the mapped discrete values as code complexity indexes. And, the threshold interval with smaller original metric data is mapped into a larger code complexity index. For example, when the value of n is 4, the corresponding relationship between the threshold interval where the original metric data is located and the mapped code complexity index is: (0, t)1]The code complexity index of the interval is 4, (t)1,t2]The code complexity index of the interval is 3, (t)2,t3]The code complexity index of the interval is 2, (t)3,t4]the code complexity index of the interval is 1, (t)4And ∞) interval is 0. The values of the code complexity indexes are numerical data.
And S220, carrying out gradual longitudinal aggregation on the code complexity indexes of the code segments to obtain a first aggregation score.
Specifically, the longitudinal aggregation may be performed from bottom to top according to multiple levels of the code complexity indexes of multiple code segments, where from bottom to top refers to aggregation from the bottom layer of the code segment to the upper layer thereof, so that not only can the code complexity condition of each level be fully collected, but also when the code complexity is high and there may be problem codes in multiple code segments, the output result may be detected according to the collected software code complexity, and the code segments with problems may be located by tracing back from top to bottom.
And S230, transversely aggregating the first aggregation scores to obtain second aggregation scores, and outputting the second aggregation scores as code complexity.
further, the code complexity index includes: a Method Type indicator for multiple dimensions and/or a Type indicator for multiple dimensions. The Method type indexes include, but are not limited to, the Circle Complexity (CC) of a code segment of software to be evaluated, the number of active Lines (LOCM) of a Method, the number of parameters (NOP) of a Method and the maximum nesting level number (MND) of a Method; the Type indicators include, but are not limited to, the number of member methods (NOM), the number of member variables (NOF), and the number of Weighted Methods (WMC) of the code snippet of the software to be evaluated. By comprehensively measuring data of multiple indexes of the code segment under multiple dimensions, the complexity of the software code can be comprehensively, deeply and accurately detected.
The embodiment of the invention provides a method for detecting software code complexity, which adopts a step-by-step longitudinal aggregation mode to detect and evaluate the code complexity of software to be evaluated, and the code complexity indexes of a plurality of code segments at the bottommost layer are aggregated upwards step by step, so that the code complexity conditions of all levels can be fully collected, and a comprehensive and deep complexity detection result is formed.
Example two
Based on the method for detecting the complexity of the software code described in the previous embodiment, the present embodiment further refines the method. Fig. 3 is a flowchart illustrating a method for detecting software code complexity according to a second embodiment of the present invention, as shown in fig. 3, the method includes:
s310, code complexity indexes of a plurality of code segments of the software to be evaluated are obtained. The content of this step S310 is the same as that of the above step S210.
and S320, longitudinally aggregating the code complexity indexes of the code fragments according to the hierarchical sequence of any layers of the class layer, the file layer, the module layer and the project layer to obtain a first aggregation score.
further, the step-by-step longitudinal aggregation of the code complexity indexes of the plurality of code segments includes: and carrying out gradual longitudinal aggregation on the code complexity indexes of the code segments by using a weak item intensive aggregation function. The weak term intensive aggregation function is an aggregation function which can give a smaller value a larger weight without changing a value range.
Further, the weak term intensive aggregation function may be:
Wherein f (x) is the overall aggregation score of the hierarchy to which the vertical aggregation is directed, xiAn aggregation score or code complexity index for each aggregated unit of the hierarchy for which the vertical aggregation is directed. Specifically, the aggregated unit refers to a level next to a level to which the current vertical aggregation is directed in the step-by-step vertical aggregation process. For example, when f (x) is the aggregate score for the entirety of the module hierarchy for which the vertical aggregation is directed, xithe value can be taken as the aggregate score of each file level for which the vertical aggregation is directed.
In a practical application scenario, as mentioned above, raw metric data of a Method Type and a Type index of multiple dimensions may be obtained by the index calculator, and the raw metric data may be mapped to obtain a code complexity index. In order to facilitate the positioning and indexing of each level of a plurality of code fragments in software to be evaluated, the data set of the code complexity index can be expressed as data { p ═ p1,p2...pi,m1,m2...mjin which p isiThe method, the class or the file of the software to be evaluated is the position information of the code segment of the software to be evaluated, and the position information comprises but is not limited to a project name, a module name, a file name, a class name and/or a method name. m isjthe code complexity index of the method, class or file of the code segment of the software to be evaluated. The stepwise longitudinal polymerization may specifically comprise the steps of:
Step one, position information p is usediThe position information of the item name, the module name, the file name, the class name and the like contained in the index is used as an index, and the code complexity corresponding to the Method Type index and the Type index under the same index is foundIndexes are obtained, and a plurality of code complexity indexes under the two dimensions are longitudinally aggregated according to the weak term intensive aggregation function, so that an aggregation score of class levels is obtained;
Secondly, using position information such as project names, module names, file names and the like as indexes, finding code complexity indexes corresponding to different indexes of a class hierarchy under the same index, and longitudinally aggregating the code complexity indexes of the same index type of a plurality of classes according to the weak item intensive aggregation function to obtain an aggregation score of the file hierarchy;
step three, using position information such as project names, module names and the like as indexes, finding code complexity indexes corresponding to different indexes of a file level under the same index, and longitudinally aggregating the code complexity indexes of the same index type of a plurality of files according to the weak item intensive aggregation function to obtain an aggregation score of the module level;
And step four, using the position information such as the item name and the like as an index, finding code complexity indexes corresponding to different indexes of the module level under the same index, and longitudinally aggregating the code complexity indexes of the same index type of a plurality of modules according to the weak item intensive aggregation function to obtain an aggregation score of the item level, namely a first aggregation score.
Further, in the above-mentioned step-by-step longitudinal aggregation process, the aggregation scores corresponding to each step can be adjusted to counter the long-tail distribution effect.
Specifically, as mentioned above, based on knowledge and experience in the field, the original metric data of the code complexity index often exhibits long tail distribution, and in order to reduce errors of the code complexity index caused by the long tail distribution effect and make the error more consistent with a real scene, an adjustment may be made to the original metric data and/or the preset percentile of the aggregation score corresponding to each level. For example, if all possible values of the aggregation score corresponding to the class hierarchy are set to 0,1, 2,3, and 4, the percentiles corresponding to the intervals [0,1), [1,2), [2,3), and [3,4] may be preset to be 95%, 99%, 99.5%, and 99.9%, based on knowledge and experience in the art. Taking an interval [0,1) corresponding to 95% of percentiles as an example, taking a certain point in the threshold interval as a percentile, so that the aggregate scores of 95% in the threshold interval are smaller than the aggregate score corresponding to the percentile, which is beneficial to reducing errors caused by long tail distribution effect of the detection result of software code complexity.
S330, transversely aggregating the first aggregation scores to obtain second aggregation scores, and outputting the second aggregation scores as code complexity. The content of this step S330 is the same as that of the above step S230.
Further, the transversely aggregating the second aggregation score to obtain a second aggregation score comprises: and calculating the average value of the first aggregation scores to obtain second aggregation scores.
Specifically, by calculating an average value of the first aggregation scores of the plurality of code segments, a second aggregation score, which is a software code complexity detection result of integrating the code complexity indexes of the plurality of dimensions of the plurality of code segments, can be obtained.
The embodiment of the invention provides a method for detecting software code complexity, which adopts a step-by-step longitudinal aggregation mode to detect and evaluate the code complexity of software to be evaluated, and the code complexity indexes of a plurality of code segments at the bottommost layer are aggregated upwards step by step, so that the code complexity conditions of all levels can be fully collected, and a comprehensive and deep complexity detection result is formed.
EXAMPLE III
Fig. 4 is a schematic structural diagram of a device for detecting software code complexity according to an embodiment of the present invention, the device is mainly used for executing the method steps shown in fig. 2, and as shown in fig. 4, the device includes:
A code complexity index obtaining module 410, configured to obtain a code complexity index of a code segment of software to be evaluated;
The vertical aggregation module 420 is configured to perform vertical aggregation step by step on the code complexity indexes of the multiple code segments to obtain a first aggregation score;
and a transverse aggregation module 430, configured to transversely aggregate the first aggregation score to obtain a second aggregation score, and output the second aggregation score as the code complexity.
further, the code complexity index includes:
A method type indicator for multiple dimensions and/or a type indicator for multiple dimensions.
Further, the step-wise longitudinal aggregation comprises:
and carrying out longitudinal aggregation according to the hierarchical sequence of any plurality of layers in the class layer, the file layer, the module layer and the project layer to obtain a first aggregation score.
Further, the step-by-step longitudinal aggregation of the code complexity indexes of the plurality of code segments includes:
and carrying out gradual longitudinal aggregation on the code complexity indexes of the code segments by using a weak item intensive aggregation function.
Further, the weak term intensive aggregation function is:
Wherein f (x) is the overall aggregation score of the hierarchy to which the vertical aggregation is directed, xiAn aggregation score or code complexity index for each aggregated unit of the hierarchy for which the vertical aggregation is directed.
further, the transversely aggregating the second aggregation score to obtain a second aggregation score comprises:
and calculating the average value of the first aggregation scores to obtain second aggregation scores.
Further, in the process of the longitudinal aggregation step by step, the aggregation scores corresponding to each step are adjusted to resist the long tail distribution effect.
The embodiment of the invention provides a device for detecting the complexity of a software code, which detects and evaluates the code complexity of software to be evaluated by adopting a step-by-step longitudinal aggregation mode, and the code complexity indexes of a plurality of code segments at the bottommost layer are aggregated upwards step by step, so that the code complexity conditions of all levels can be fully collected, a comprehensive and deep complexity detection result is formed, and in addition, the code segments with problems in the aspect of code complexity can be conveniently positioned by developers by backtracking the complexity detection process of the step-by-step aggregation.
Example four
The third embodiment describes an overall architecture of a device for detecting software code complexity, and the functions of the device can be implemented by an electronic device, as shown in fig. 5, which is a schematic structural diagram of the electronic device according to the embodiment of the present invention, and specifically includes: a memory 510 and a processor 520.
A memory 510 for storing programs.
in addition to the programs described above, the memory 510 may also be configured to store other various data to support operations on the electronic device. Examples of such data include instructions for any application or method operating on the electronic device, contact data, phonebook data, messages, pictures, videos, and so forth.
the memory 510 may be implemented by any type or combination of volatile or non-volatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
A processor 520, coupled to the memory 510, for executing programs in the memory 510 for:
Acquiring code complexity indexes of a plurality of code segments of software to be evaluated;
carrying out longitudinal aggregation on the code complexity indexes of the code segments step by step to obtain a first aggregation score;
And transversely aggregating the first aggregation scores to obtain second aggregation scores, and outputting the second aggregation scores as the code complexity.
the above specific processing operations have been described in detail in the foregoing embodiments, and are not described again here.
Further, as shown in fig. 5, the electronic device may further include: communication components 530, power components 540, audio components 550, display 560, and other components. Only some of the components are schematically shown in fig. 5, and it is not meant that the electronic device comprises only the components shown in fig. 5.
The communication component 530 is configured to facilitate wired or wireless communication between the electronic device and other devices. The electronic device may access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 530 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 530 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
A power supply component 540 provides power to the various components of the electronic device. The power components 540 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for an electronic device.
The audio component 550 is configured to output and/or input audio signals. For example, the audio assembly 550 includes a Microphone (MIC) configured to receive external audio signals when the electronic device is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal may further be stored in the memory 510 or transmitted via the communication component 530. In some embodiments, audio assembly 550 also includes a speaker for outputting audio signals.
the display 560 includes a screen, which may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.

Claims (10)

1. A method for detecting software code complexity is characterized by comprising the following steps:
Acquiring code complexity indexes of a plurality of code segments of software to be evaluated;
Carrying out longitudinal aggregation on the code complexity indexes of the code segments step by step to obtain a first aggregation score;
And transversely aggregating the first aggregation scores to obtain second aggregation scores, and outputting the second aggregation scores as the code complexity.
2. the method of claim 1, wherein the code complexity indicator comprises:
A method type indicator for multiple dimensions and/or a type indicator for multiple dimensions.
3. The method of claim 1, wherein the progressive vertical aggregation comprises:
And carrying out longitudinal aggregation according to the hierarchical sequence of any plurality of layers in the class layer, the file layer, the module layer and the project layer to obtain the first aggregation score.
4. the method of claim 1, wherein performing a progressive vertical aggregation of the code complexity indicators for the plurality of code fragments comprises:
And carrying out gradual longitudinal aggregation on the code complexity indexes of the plurality of code segments by using a weak term intensive aggregation function.
5. The method of claim 4, wherein the weak term intensive aggregation function is:
Wherein f (x) is the overall aggregation score of the hierarchy to which the vertical aggregation is directed, xian aggregation score or code complexity index for each aggregated unit of the hierarchy for which the vertical aggregation is directed.
6. The method of claim 1, wherein said transversely aggregating said second aggregation score to obtain a second aggregation score comprises:
And calculating the average value of the first aggregation scores to obtain the second aggregation scores.
7. the method of claim 1, wherein during the step-wise vertical aggregation, the aggregation scores corresponding to each step are adjusted to counter the long-tail distribution effect.
8. An apparatus for detecting software code complexity, comprising:
The code complexity index acquisition module is used for acquiring a code complexity index of a code segment of the software to be evaluated;
The longitudinal aggregation module is used for carrying out longitudinal aggregation on the code complexity indexes of the code segments step by step to obtain a first aggregation score;
And the transverse aggregation module is used for transversely aggregating the first aggregation scores to obtain second aggregation scores, and outputting the second aggregation scores as the code complexity.
9. the apparatus of claim 8, wherein performing a progressive vertical aggregation of code complexity indicators for the plurality of code fragments comprises:
And carrying out gradual longitudinal aggregation on the code complexity indexes of the plurality of code segments by using a weak term intensive aggregation function.
10. An electronic device, comprising:
A memory for storing a program;
A processor, coupled to the memory, for executing the program for:
Acquiring code complexity indexes of a plurality of code segments of software to be evaluated;
carrying out longitudinal aggregation on the code complexity indexes of the code segments step by step to obtain a first aggregation score;
And transversely aggregating the first aggregation scores to obtain second aggregation scores, and outputting the second aggregation scores as the code complexity.
CN201810590045.7A 2018-06-08 2018-06-08 software code complexity detection method and device and electronic equipment Pending CN110580218A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810590045.7A CN110580218A (en) 2018-06-08 2018-06-08 software code complexity detection method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810590045.7A CN110580218A (en) 2018-06-08 2018-06-08 software code complexity detection method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN110580218A true CN110580218A (en) 2019-12-17

Family

ID=68810277

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810590045.7A Pending CN110580218A (en) 2018-06-08 2018-06-08 software code complexity detection method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN110580218A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112711530A (en) * 2020-12-28 2021-04-27 航天信息股份有限公司 Code risk prediction method and system based on machine learning
WO2023144140A1 (en) * 2022-01-28 2023-08-03 Codescene Ab An approach for classifying source code with a code quality indicator
WO2023179578A1 (en) * 2022-03-21 2023-09-28 中兴通讯股份有限公司 Code metric method and apparatus, device, and medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103605607A (en) * 2013-12-02 2014-02-26 中标软件有限公司 Software complexity analysis system and method
CN103838671A (en) * 2014-01-26 2014-06-04 北京理工大学 Software defect measuring method based on complex network
CN107102948A (en) * 2017-05-19 2017-08-29 青岛大学 A kind of software architecture complexity measure method based on UML
CN107239396A (en) * 2017-05-11 2017-10-10 东南大学 A kind of Software Evolution appraisal procedure measured based on code cyclomatic complexity
US20170300318A1 (en) * 2016-04-18 2017-10-19 Accenture Global Solutions Limited Identifying low-quality code

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103605607A (en) * 2013-12-02 2014-02-26 中标软件有限公司 Software complexity analysis system and method
CN103838671A (en) * 2014-01-26 2014-06-04 北京理工大学 Software defect measuring method based on complex network
US20170300318A1 (en) * 2016-04-18 2017-10-19 Accenture Global Solutions Limited Identifying low-quality code
CN107239396A (en) * 2017-05-11 2017-10-10 东南大学 A kind of Software Evolution appraisal procedure measured based on code cyclomatic complexity
CN107102948A (en) * 2017-05-19 2017-08-29 青岛大学 A kind of software architecture complexity measure method based on UML

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112711530A (en) * 2020-12-28 2021-04-27 航天信息股份有限公司 Code risk prediction method and system based on machine learning
WO2023144140A1 (en) * 2022-01-28 2023-08-03 Codescene Ab An approach for classifying source code with a code quality indicator
WO2023179578A1 (en) * 2022-03-21 2023-09-28 中兴通讯股份有限公司 Code metric method and apparatus, device, and medium

Similar Documents

Publication Publication Date Title
CN109242135B (en) Model operation method, device and business server
CN110580217B (en) Software code health degree detection method, processing method, device and electronic equipment
CN111915020B (en) Updating method and device of detection model and storage medium
CN110580218A (en) software code complexity detection method and device and electronic equipment
JP6869347B2 (en) Risk control event automatic processing method and equipment
CN105320701B (en) Screening technique, device and the terminal of function point test implementation
CN110046633B (en) Data quality detection method and device
CN111294819A (en) Network optimization method and device
CN110221953A (en) Test result analysis method, apparatus, server and storage medium
CN112131079B (en) Data monitoring method, device, electronic equipment and storage medium
CN107678934A (en) Interim card index selection method and device
CN111506731A (en) Method, device and equipment for training field classification model
CN107943571B (en) Background application control method and device, storage medium and electronic equipment
CN109688535A (en) Determine method, apparatus, electronic equipment and the medium in hotspot geographical location
US20180313799A1 (en) Data quality control using a correlated sensor group
CN114707548A (en) Abnormal waveform capturing method and device, electronic equipment and storage medium
CN104394039B (en) One kind is based on Sigmoid exponential models network performance maturity assessment system and its evaluation method
CN111832256B (en) Method and related device for marking information of examination drawing
CN113869599A (en) Fish epidemic disease development prediction method, system, equipment and medium
CN109995549A (en) A kind of method and device for assessing Flow Value
CN109597700B (en) Disk life prediction method and related device
CN110489104A (en) Suitable for the mathematical formulae processing method and processing device of experimental data, storage medium
CN116541238A (en) Log file acquisition method and device, electronic equipment and readable storage medium
US20150149235A1 (en) Methods and systems to improve a quality of data employed by a healthcare analytics system
CN110866003B (en) Index value number estimation method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20191217