Skip to main content

UTURN Style Guide

The UTURN Style Guide can be found under ./checkstyle/uturn_style.xml. It is based on Google's Java Style Guide.

First changes

Various changes were made to the style guide where we did not wish to change our style, but rather changed the style guide.

  1. Max line length to 150 rather than 80.
  2. Some fixes to properly allow switch.
  3. Indentation of 4 spaces rather than 2.

Javadoc

By default Google's style guides mandate a Javadoc comment for each public method with >2 lines.

/** Maps rating details.
*
* @param averageRating float
* @param totalRatings float
* @return RatingDto
*/
public static RatingDto mapRatingDto(float averageRating, int totalRatings) {
return RatingDto.builder()
.averageRating(averageRating)
.totalRatings(totalRatings)
.build();
}

By default the Style Guide would mandate a comment. The shown comment does not add any value. There isn't really a comment that could add any value here. In most cases the method name + types and names of arguments are sufficient documentation.

Downsides of comments can still be present, the comment has gotten out of date. (Fixed in commit 3e3e05599d42b302bbbea1082cbde9e5b1d5d442.)

The goal is to define the checkstyle rule to ensure it doesn't apply when comments have no added value, but only downsides. Therefore we have chosen to only enforce comments at method size >20. In that case there should at least be a comment explaining why such a long method has to exist, which has some added value.