Casa de Quixote is a small, state-run retirement community in La Mancha, in central Spain. Sergio continues his job as the sole developer of software managing hundreds of residents.

It's always a bonus when the same brave soul delivers multiple WTFs for our exasperation. Our very own man from La Mancha has been doing a lot of refactoring lately, retaining the GUI of his employer's Assistance-Management System while replacing the zany consultantware underneath with vastly improved code.

Now, I wouldn't blame you for viewing Sergio's hack-and-burn mentality with a skeptical eye, wondering if the legacy code was truly awful or just a victim of Not Invented Here. As justification for his crusade, Sergio sent us this representative snippet of his predecessors' work. Let's play Count The WTFs:

// "concertado" = "partner", and the method returns a boolean indicating whether 
// the patient's nursing home belongs to Casa de Quixote or one of its partners
public ActionForward concertado(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    GestionSolicitudFormBean gestionSolicitudFormBean = (GestionSolicitudFormBean)form; //"Gestion Solicitud" = "Patient Episode"

    try {
        Calendar calendar = new GregorianCalendar();
        Espacio centro = gestionSolicitudFormBean.getEntidad().getCentro(); // get patient's nursing home
        calendar.setTime(centro.getFechaC()); // get nursing home's creation date
        boolean esReinaSofia = centro.getNombre().equals("Centre de Dia Reina Sofia");
        String resultado = "false";
        if ((calendar.get(Calendar.DAY_OF_MONTH) == 16
            && calendar.get(Calendar.MONTH) == Calendar.MAY
            && calendar.get(Calendar.YEAR) == 2013) || esReinaSofia) {
    } catch (Exception e) {
        log.error("Error en AdmAbstractSolicitudAccion, error al enviar el "
            + "tipo de centro (concertado o no): " + e.getMessage(), e);
    return mapping.findForward("");

Did you catch them all? I got four:

  1. The response from the service call identifies its content as XML when it only ever contains the strings "true" or "false"
  2. The creation date of the nursing home is used to identify whether that home is part of Casa de Quixote or one of its independent partners; apparently all the homes CdQ owns were added to the database on the same day...
  3. ...Except for one, and there's a special case hard-coded in there to ensure it's also identified as one they own
  4. And in case you think I've got things backwards, Sergio assures us that despite this method being called "partner", it returns true when the nursing home isn't a partner and false when it is.

When asked what made this delicious morsel of ridiculous business logic necessary, Sergio explained that the previous developers didn't want to add database fields to those defined in the spec, so they took advantage of the fact that all the owned homes were added on the day the system was rolled out and bestowed responsibility for identifying partner homes on the lowly Creation Date field. When Centre de Dia Reina Sofia was added a year later, they likewise didn't want to back-date its creation. You've got to hand it to those Highly-Paid Consultants: though willing to commit WTFs like this in Java, at least they went to great lengths to keep their hands off the database.

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