Code quality

IT1901 Fall 2020 - 11th Lecture

Code quality

Code quality

  • automated tests

  • coding standards and consistent formatting

  • check for higher level types of errors (bug patterns)

Tools for automatic code checking

Checkstyle

  • static analysis

  • finds errors like

    • references to variables with undefined value

    • variables that are never used

    • syntax and coding standards violations

    • dead code blocks

Checkstyle (2)

  • naming conventions

  • line length

  • whitespace

  • Javadoc comments

  • annotations

Checkstyle (3)

  • can be configured to use a certain set of checks

  • extendable - one can write own checks

  • plugins for IDEs

Checkstyle examples

Spotbugs

  • checks bytecode and not the source

  • looks for "bug patterns"

  • example:

An apparent infinite loop (IL_INFINITE_LOOP)
This loop doesn't seem to have a way to terminate (other than by perhaps throwing an exception).

Spotbugs (2)

  • extendable

  • plugins for Maven Gradle Ant

  • Eclipse IDE integration

Spotbugs examples

Norwegian University of Science and Technology