Saturday, April 20, 2013

SevNTU Checkstyle version 1.8.0


We finished new version of our extension for Checkstyle - release 1.8.0, new and noteworthy.

new NestedTernaryCheck.
Main idea of check to forbid to use nested ternary conditions, as it hard to read and debug them then
if(){}else{},  example:
int smth = (a == b) ? -1 : (c == d) ? 0 : 1;
this code is very compact, but it is disaster for other developer to understand and debug this code. In this case we could say logic is archived, and need spend extra time to extract logic over over again during debug, and that compact view does not contribute to performance.

Expected code is substitution by function:
int smth = calculateSmth(a, b, c, d);
or:
int smth = -1;
if (a!=b) {
  if (c ==d) {
      smth = 0;
  } else {
      smth = 1;
  }
}
The only benefits to use such statement is to declare "final" variable, so this is available as option in check, but it is not selected by default.


new ForbidReturnInFinalBlockCheck.
Return statement in final block is allowed by compilation. But it is highly non-recommended to use it, as it change return of main logic.
Example:
try { 
   return true; 
} finally { 
   return false; 
}
More info and discussion is here.


Bug fixing for existing checks:
 - Message improvement in ChildBlockLengthCheck,
 - bug fixing in AvoidHidingCauseExceptionCheck and OverridableMethodInConstructorCheck,
 - ignore methods now support RegExp at ReturnCountCheckExtended.


Note:
Available as EclipseCS extension and as extension for maven-checkstyle-plugin. Install instructions.

No comments:

Post a Comment