Highly Paid Consultants™ should be knowledgeable in their claimed area of expertise. One would assume that any consultant would have a basic understanding of what passing parameters to a function is for and how to utilize that concept in their chosen programming language.

One would be wrong.

Gustav sent an example of how the Highly Paid Consultants their firm was using managed to screw up something as simple as taking a substring using the built-in functions, and then replicated the damage by brute-forcing the code in lieu of passing in a simple parameter to an ever-so-slightly more generic function:

public class StringUtils {
  private int ZERO = 0;

  private int TWENTYNINE = 29;
  private int THIRTY = 30;
  private int THIRTYONE = 31;
  // ...
  private int FORTYEIGHT = 48;
  private int FORTYNINE = 49;
  private int FIFTY = 50;

  public String string30(String in){ 
    if (in.length() > THIRTY){ 
      return in.substring(ZERO, TWENTYNINE); 
    } else { 
      return in; 
  } 

  public String string31(String in){ 
    if (in.length() > THIRTYONE){ 
      return in.substring(ZERO, THIRTY);
    } else { 
      return in; 
  } 

  // ...

  public String string50(String in){ 
    if (in.length() > FIFTY){ 
      return in.substring(ZERO, FORTYNINE); 
    } else { 
      return in; 
  } 
}

I'm not even going to go into what would happen if someone passed in a null pointer.

For those who don't know Java, someString.substring(0,29) returns the characters at indices 0..28. This means that those functions will return the entire string for inputs <= the given length, but only the first n-1 characters if the input string exceeds that length, which is probably not what they wanted.

It's not like they could have written:

public class StringUtils {
  public String stringPrefix(String in, int maxLen){ 
    if (in == null) {
       return null;
    }
    if (maxLen < 1) {
       return "";
    }
    return in.length() <= maxLen
             ? in
             : in.substring(0,maxLen);
  } 
}
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!