This question already has an answer here:
I want a feasible way to compare my project with my friend's project. I first thought it was enough to compare based on the number of code lines. But for some reason, people kept saying "LOC is not a good measure".
So, is the following method (I cooked up myself and I don't know if there is anything like this) good enough to compare my project with my friend's project?
We can calculate the
effort_factor using the following algorithm:
effort_factor = 0 mini_method = 0.01 proper_method = 1 min_avg_LOC_of_each_method = 6 for each_class in source_code: avg_LOC_of_each_method = LOC(each_class)/no_of_methods(each_class) for each_method in each_class: if avg_LOC_of_each_method < min_avg_LOC_of_each_method: avg_LOC_of_each_method = min_avg_LOC_of_each_method if LOC(each_method) < avg_LOC_of_each_method: effort_factor += mini_method else: effort_factor += proper_method return effort_factor
Definitions for the symbols used here:
effort_factor: The measured amount of effort delivered by the developer (If the developer was maintaining an existing code, the absolute difference between the initially measured
effort_factorand the final
effort_factormust be the developer's contributed effort factor assuming he didn't reduce the functionality of the source-code by removing any existing features).
mini_method: The score-value (or weight) given to methods that contain less-than-average number of lines of code.
proper_method: The score-value (or weight) given to methods that contain more-than-average number of lines of code (these methods are assumed to be vital for the task carried over by the class).
min_avg_LOC_of_each_method: In cases where there are classes with no methods that exceed 6 lines of code, we must ensure that all the methods of the class are considered to be mini-methods (small methods). This constant that ensures that
avg_LOC_of_each_methodvalue never gets below 6.
avg_LOC_of_each_method: holds the number of lines of code per method in a class.
LOC(): computes the number of lines of code (for either a class or a method).
The basic idea of this method is to count the number of methods instead of the code-lines. Also we can assume, methods that have too less number of lines don't add much value to the code, as they can't solve any vital problems. At the same time methods with many lines of code can be assumed to solve a vital problem and hence can be given a greater weight-value.
Is this method feasible to measure and compare source codes? Or are there any flaws in it?