-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A new CC metric that takes nesting into account #35
Comments
I will not classify this as a bug, as I think this is actually a possible new metric to CK! Would you be willing to implement it yourself? I can help you by giving you tips and feedback in a PR! |
@mauricioaniche
where d(m) denotes the depth of the method m. For example, consider the following code: public int getPayAmount() {
int result = 0;
if (isDead)
result = deadAmount();
else {
if (isSeparated)
result = separatedAmount();
else {
if (isRetired)
result = retiredAmount();
else
result = normalPayAmount();
}
}
return result;
} The depth of the method (d(m)) is 3. Indeed, if the depth of a method is implemented as a new metric, the modified WMC will be automatically computed. |
Is Is that it? |
Not exactly. For any nested blocks, the max depth of that block added to public int m1(){
statement 1;
for(int i=0; i< 10; i++){
statement 2;
if(cond)
statement 3;
}
statement 4;
if(cond2) {
statement 5;
statement 6;
if(cond3) {
statement 7;
}
}
if(cond4) {
statement 8;
statement 9;
if(cond5) {
statement 10;
}
}
statement 11;
return 100;
} The max depth is 2. However, the |
@mauricioaniche |
I did not read the paper yet, so, sorry for my questions! But isn't then |
No. Although most of the cases are true, there are some situations that |
From the paper, it seems that, all we need to do in the WMC implementation is to give a weight of 1, if the (There's also the corner case of a block returning early, then, next ones in that nested block should be considered 1 again) Does that make sense to you? |
Yes. This is exactly what I understood from the paper. |
By definition, the CC metric does not take into account the nesting levels of the method. For example, consider the following Python source code:
By refactoring this code, we get:
As you can see, By applying a popular technique named Replace Nested Conditional with Guard Clauses, the source code structure would improve a lot. However, the CC metric does not change (by definition).
Some researchers have proposed a few solutions. Surprisingly, the best solution (in my opinion) has the minimum citation link .
The text was updated successfully, but these errors were encountered: