When Maarten first saw the utility function below, he couldn’t imagine why converting a number from float to double required a string intermediate. Fortunately, whoever wrote this code followed best practices: their comment not only explained what the code is doing, it also explained why.

Pennywise in the sewer


/**
	 * This method converts a float to a double.
	 * Because the model uses doubles in calculations while the matrices holds floats.
	 * @param number
	 * The float value to convert to a double
	 * @param accurate
	 * Flag to specify whether to use an accurate conversion from float to double
	 * or to use a less accurate conversion. Accurate means strings will be used
	 * what may result in a bit slower performance. Not accurate means typecasting
	 * will be used, this result in a fault since a double has a higher precision
	 * then a float.
	 */
	 double floatToDouble(float number, boolean accurate) {
	 	if (accurate) {
	 		return Double.parseDouble(Float.toString(number));
	 	}
	 	return number;
	 }

While Maarten appreciates the author’s effort, he’s not entirely convinced that comments alone can a sensible method make…

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!