Why choosing (public) open source is a so keen choice

I’m spending some days extending an aged OpenCMS project (so aged as OpenCMS 7.0) to include some new features. It’s not a nice task but someone has to perform it.

The facts

I’m trying not to inspect all this crazy code, but sometimes I simply can’t apart my eyes from it. Let me share with you this little piece of art, worthy of appearing in The Daily WTF or so. I want to specify that this lines are written (supposedly) in Java.

String orden = "";
if ((request.getParameter("orden") != null) && (request.getParameter("orden") != "")) {
	orden = request.getParameter("orden");
	if (orden.compareTo("") != 0) {
		logger.info("entrada1 con " + this.controlUsuario.listaUsuariosNombreApellidosUnidad(
		    nombre, apellidos, unidad, extension, fijo, tipo, empresa, orden, inactivos, 
		    idGrupo).size());
		request.setAttribute("resultados", this.controlUsuario.listaUsuariosNombreApellidosUnidad(
		    nombre, apellidos, unidad, extension, fijo, tipo, empresa, orden, inactivos, idGrupo));
		myModel.put("resultados", this.controlUsuario.listaUsuariosNombreApellidosUnidad(
		    nombre, apellidos, unidad, extension, fijo, tipo, empresa, orden, inactivos, idGrupo));
	} else {
		logger.info("entrada2 con " + this.controlUsuario.listaUsuariosNombreApellidosUnidad(
		    nombre, apellidos, unidad, extension, fijo, tipo, empresa, "apellidos", inactivos, 
		    idGrupo).size());
		request.setAttribute("resultados", this.controlUsuario.listaUsuariosNombreApellidosUnidad(
		    nombre, apellidos, unidad, extension, fijo, tipo, empresa, "apellidos", inactivos, 
		    idGrupo));
		myModel.put("resultados", this.controlUsuario.listaUsuariosNombreApellidosUnidad(nombre, 
		    apellidos, unidad, extension, fijo, tipo, empresa, "apellidos", inactivos, idGrupo));
	}
} else {
	logger.info("entrada3 con " + this.controlUsuario.listaUsuariosNombreApellidosUnidad(nombre, 
	    apellidos, unidad, extension, fijo, tipo, empresa, "apellidos", inactivos, idGrupo).size());
	request.setAttribute("resultados", this.controlUsuario.listaUsuariosNombreApellidosUnidad(nombre,
	    apellidos, unidad, extension, fijo, tipo, empresa, "apellidos", inactivos, idGrupo));
	myModel.put("resultados", this.controlUsuario.listaUsuariosNombreApellidosUnidad(nombre, apellidos,
		unidad, extension, fijo, tipo, empresa, "apellidos", inactivos, idGrupo));
}

A client payed for this work as if it were developed by a Senior Java Developer supervised by a Senior Java Analyst.

The analysis

For those of you not used to read Java code, I’m going to point out some curiosities:

  • Strings are compared by using equals String type function in Java, so request.getParameter("orden") != "" will not work as expected in any case
  • As this programmer (or maybe other) realised that this condition was not working, he decided to use that other fancy expression orden.compareTo("") != 0, which works but is not so usual. Surprisingly, he left the incorrect comparison expression in the previous line
  • These are just only minor considerations, I’m saving the best for last. Despite objects are not known by this developer (10 arguments functions, really?), that controlUsuario.listaUsuariosNombreApellidos(...) included three times in every case appear to be dangerous. Let me check implementation by using a simple CMD+Click… Bingo!
    • Every controlUsuario.* is a DAO invocation, which is performing a full table scan query on database
    • 3x time for every search that can be simply avoided by using your fingers (and your mind) instead of CMD+C

The thinking

Open Source and public source code is always a better choice than closed code.

If that sample we were talking above were published in some kind of tool like GitHub, any developer had discovered this (big) defects and (even) he could collaborate to improve it. However, as it was a closed project, it has remained hidden during years, consuming database resources without limits and wasting thousand of hours from users in front of the screen.

After that, are you yet trusting in those closed systems? Not me.

Note Obviously I’m referring as “close” to that extension developed for OpenCMS, not to OpenCMS itself which is a clean sample of Open Source product

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s