Determining code complexity scores
In one example of the disclosure, code lines for a software program are received, the code lines including a unit of code lines. Code entities within the unit are identified. Each code entity includes a line or consecutive lines of code implementing a distinct program requirement or defect fix for the program. Context changes are identified within the unit, each context change including an occurrence of a first code line set implementing an entity, adjacent to a second code line set implementing another entity, within a same code scope. A code complexity score is determined based upon counts of entities identified and context changes identified within the unit, and upon counts of code lines and entities within the program.
1. A system, comprising:
a processor; and
a memory storing instructions that when executed by the processor cause the processor to:
receive a unit of code lines of a software program;
identify a plurality of entities within the unit of code lines, wherein each entity includes a set of code lines implementing a distinct program requirement or defect fix for the software program;
identify context changes within the unit of code lines, wherein each context change is an occurrence of a first entity that includes a first code line set implementing a first program requirement or defect fix, adjacent to a second entity that includes a second code line set implementing a second program requirement or defect fix, within a same code scope of the software program;
determine a code complexity score of the unit of code lines based upon a total number of entities identified and a total number of context changes identified within the unit of code lines, and upon total numbers of code lines and entities within the software program; and
generate a recommendation to rework the unit of code lines of the software program based on a comparison of the determined code complexity score and a previously determined code complexity score.
2. The system of claim 1 , wherein the code lines of the unit are consecutive code lines.
3. The system of claim 1 , wherein, to identify each entity within the unit of code lines, the instructions are to cause the processor to access metadata tags within the unit of code lines to determine a set of code lines that implements a distinct program requirement or defect fix.
4. The system of claim 1 , wherein, to identify each entity within the unit of code lines, the instructions are to cause the processor to access comments within the unit of code lines to determine a set of code lines that implements a distinct program requirement or defect fix.
5. The system of claim 1 , wherein the instructions are to cause the processor to determine the code complexity score based upon the formula
code complexity=( E n *S n )/(LOC* E t )
wherein E n is the total number of the entities identified in the unit of code lines, S n is the total number of the context changes within the unit of code lines, LOC is the total number of lines of code within the software program, and E t is the total number of entities within the software program.
6. The system of claim 1 , wherein the same code scope is a same scope of method in the software program.
7. The system of claim 1 , wherein the same code scope is one of a same class, a same file, a same loop, and a same closure.
8. The system of claim 1 , wherein the code complexity score is a first code complexity score, and wherein the instructions are to cause the processor to access a database to obtain the previously determined code complexity score, and determine the recommendation to rework the software program based upon a comparison of the first code complexity score to the previously determined score.
9. The system of claim 1 , wherein the instructions are to cause the processor to send the determined code complexity score to a developer software application or developer computing device.
10. A non-transitory computer readable storage medium storing instructions that when executed cause a processing resource to:
receive a unit of code lines of a software program;
identify a plurality of entities within the unit of code lines, wherein each entity includes a set of code lines implementing a distinct program requirement or defect fix for the program, and apply a relevancy filter to identify from the entities a set of relevant entities;
identify context changes within the unit of code lines, wherein each context change is an occurrence of a first one of the relevant entities that includes a first code line set implementing a first program requirement or defect fix, adjacent to a second one of the relevant entities that includes a second code line set implementing a second program requirement or defect fix, within a same code scope of the software program;
determine a code complexity score of the unit of code lines based upon a total number of relevant entities identified and a total number of context changes between relevant entities identified within the unit of code lines, and upon total numbers of code lines and entities within the software program; and
generate a recommendation to rework the unit of code lines of the software program based on a comparison of the determined code complexity score and a previously determined code complexity score.
11. The non-transitory computer readable storage medium of claim 10 , wherein the instructions are to cause processing resource to identify the set of relevant entities according to one of a program release date, a program version, a development period, and a development team.
12. The non-transitory computer readable storage medium of claim 10 , wherein the instructions are to cause processing resource to identify the set of relevant entities according to functionality of the entities.
13. The non-transitory computer readable storage medium of claim 10 , wherein the instructions are to cause processing resource to identify the set of relevant entities according to functionality versus nonfunctionality of the entities.
14. The non-transitory computer readable storage medium of claim 10 , wherein the instructions are to cause the processor to determine the code complexity score based upon the formula
code complexity=( E n *S n )/(LOC* E t )
wherein E n is the total number of the entities identified in the unit of code lines, S n is the total number of the context changes within the unit of code lines, LOC is the total number of code lines within the software program, and E t is the total number of the entities within the software program.
15. The non-transitory computer readable storage medium of claim 10 , wherein the determined code complexity score is a first code complexity score, and wherein the instructions are to cause the processing resource to access a database to obtain the previously determined code complexity score, and determine the recommendation to rework the unit of code lines of the software program based upon a comparison of the first code complexity score to the previously determined code complexity score.
16. A method to determine code complexity scores, comprising:
identifying, by a processor of a computing device, a unit of code lines within a software program;
identifying, by the processor, a plurality of entities within the unit of code lines, wherein each entity includes a set of code lines implementing a distinct program requirement or defect fix for the software program;
identifying, by the processor, context changes within the unit of code lines, wherein each context change is an occurrence of a first entity that includes a first code line set implementing a first program requirement or defect fix, adjacent to a second entity that includes a second code line set implementing a second program requirement or defect fix, within a same code scope of the software program;
determining, by the processor, a code complexity score of the unit of code lines based upon a total number of the entities identified and a total number of the context changes identified within the unit of code lines, and upon total numbers of code lines and entities within the software program; and
generating, by the processor, a recommendation to rework the unit of code lines of the software program based on a comparison of the determined code complexity score and a previously determined code complexity score.
17. The method of claim 16 , wherein the same code scope in the software program is one of a same method, a same class, and a same closure.
18. The method of claim 16 , wherein determining the code complexity score is based upon the formula
code complexity=( E n *S n )/(LOC* E t )
wherein E n is the total number of the entities identified in the unit of code lines, S n is the total number of the context changes within the unit of code lines, LOC is the total number of code lines within the software program, and E t is the total number of the entities within the software program.
19. The method of claim 16 , wherein the determined code complexity score is a first code complexity score, and the method further comprising:
accessing a database to obtain the previously determined code complexity score, and
determining the recommendation to rework the unit of code lines of the software program based upon a comparison of the first code complexity score to the previously determined code complexity score.