When developers first got access to those new-fangled gadgets called computers, memory was a very precious resource. Applications were frequently written as a main controller that would load module overlays into memory, call a function, and then repeat as additional functions were called. It was a horrible way to code, but it was all we had. Unfortunately, as computers came equipped with more and more RAM, this habit of repeating the controller code in every file seems to be quite resilient...

Fast forward several decades, and Jeremy, like the rest of us at some point, was a newbie at his first position as a developer. The application that he was tasked with maintaining had been written by an engineer whose training apparently included learning basic JSP control-structures, and how to perform cut-n-pasting of code from A to B.

The application was almost entirely constructed of JSP's containing tens of thousands of lines of conditionals and loops nested countless levels deep, all of which was copy-pasted across almost every page. There was rarely a method to be found, and when there was, there were usually 12+ parameters, all typed as Strings. All of this would be wrapped in a try-catch block that was frequently so huge that the compiler refused to compile it, insisting that the code be broken up.

The method below represents a very rare attempt at modularity. For those who choose not to risk their sanity, it formats a floating point number to a certain precision and returns it as a String. The author was kind enough to leave their debug statements commented out, presumably to save the next guy from having to put them back in...

public String rnd(double e, double d, int numDigits) {
  String t;
  int    tempDouble;
  double f;
  //out.print(e + " + " + d);
  f= e / d;
  //out.print("<br>" + f);
  //out.print("<br>f=" + f);
  tempDouble=(int)((f)* Math.pow(10,numDigits+1));
  //out.print("<br>tempDouble=" + tempDouble);
  //out.print("<br>f=" + f);
  //out.print("<br>" +tempDouble + " " + f/Math.pow(10,numDigits));
  if (t.substring(t.indexOf('.'),t.length()).length() < numDigits+1) {
     //out.print("<br>" + t);
  if (t.compareTo("0.00")==0) {
  return t;

Naturally, it was not long before Jeremy sought sanity at his second development position.

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