Casa de Quixote is a small, state-run retirement community in La Mancha, in central Spain. Sergio is the sole developer of software managing hundreds of residents. Missing documentation, he tracks down his predecessors for help.

Miguel, manager of Casa de Quixote, told Sergio he'd find Luis at a dive in Toledo. "Just follow the empty glasses of beer," he said. Sergio did, and they led to a man: about two hundred pounds overweight, asleep at the bar, wearing a Real Madrid shirt.

"Excuse me?" Sergio poked his shoulder. "Are you Luis? I'd like to ask you some questions about the code you wrote for Casa de--"

Sergio ducked, avoiding the flying glass that passed near his cheek.

Copy-Only Programming

After several tries (and a few drinks on his tab), Sergio got Luis to talk about his time as the in-house developer at Casa de Quixote.

"I was hired after the original team finished the application," Luis said. "The management didn't have the money to pay for GenericDao's support package. I was a lot cheaper."

Sergio nodded. He pulled out his laptop. "I want to go over some code, figure out some unusual programming patterns you used." He opened a copy of the Java package and showed it to Luis. "This, for example. It's part of the code that generates bank transaction statements. Why didn't you make this thread-safe? SUFIJO could be changed during any part of this process."

public class RemesaBancariaUtil {

	private static String SUFIJO; // Suffix, one of the fields of the file
	
	public static void setSUFIJO(String sUFIJO) {
		SUFIJO = sUFIJO;
	}

	public static String primeroOpcional(Recibo recibo){

		StringBuffer sb = new StringBuffer();
		
		//Zona A
		//A1
		sb.append("56");
		//A2
		sb.append("81");
		
		//Zona B
		//B1
		if(NIF.getValor().length() ==9){
			sb.append(NIF.getValor());
		}else{
			String nif = NIF.getValor();
			while(nif.length() < 9){
				nif = "0".concat(nif);
			}
			sb.append(nif);
		}
		
		if(SUFIJO.length() ==3){
			sb.append(SUFIJO);
		}else{
			String sufijo = SUFIJO;
			while(sufijo.length() < 3){
				sufijo = "0".concat(sufijo);
			}
			sb.append(sufijo);
		}
		[…]
	}

"Oh, I dunno," Luis slurred, a drop of beer running down the side of his face.

"Okay, how about this." Sergio opened another class file. "A lot of this code is really similar. Why didn't you consolidate this into a loop, feeding in new values with each iteration? Right now this class def is almost ten thousand lines long!"

	public static String segundoOpcional(ResidenteSocio residenteSocio, FacturaServicioFacturable concepto){
		
		StringBuffer sb = new StringBuffer();
		
		//Zona A
		//A1
		sb.append("56");
		//A2
		sb.append("82");
		
		//Zona B
		//B1
		if(NIF.getValor().length() ==9){
			sb.append(NIF.getValor());
		}else{
			String nif = NIF.getValor();
			while(nif.length() < 9){
				nif = "0".concat(nif);
			}
			sb.append(nif);
		}
		
		if(SUFIJO.length() ==3){
			sb.append(SUFIJO);
		}else{
			String sufijo = SUFIJO;
			while(sufijo.length() < 3){
				sufijo = "0".concat(sufijo);
			}
			sb.append(sufijo);
		}
		
		//B2
		String b2 = residenteSocio.getCodigo().toString();
		while (b2.length() <12){
			b2 = "0".concat(b2);
		}
		sb.append(b2);
		
		//Zona C
		[…]
		
	}
	
	public static String cuartoOpcional(ResidenteSocio residenteSocio, FacturaServicioFacturable concepto){
		
		StringBuffer sb = new StringBuffer();
		
		//Zona A
		//A1
		sb.append("56");
		//A2
		sb.append("84");
		
		//Zona B
		[…]
	}
	
	public static String quintoOpcional(ResidenteSocio residenteSocio, FacturaServicioFacturable concepto){
		
		StringBuffer sb = new StringBuffer();
		
		//Zona A
		//A1
		sb.append("56");
		//A2
		sb.append("85");
		
		//Zona B
		[…]
	}

"I don't remember," Luis said. "I was having a lot of … fun, at the time, if you catch my meaning."

Sergio sighed.

A No-Loop Block

Soon, Sergio was running a hundred-euro tab in a place he'd never like to see again, and Luis had given him little insight into his coding methods. He decided to try one last tack.

"Okay, one last thing, then you can sleep on the bar all you want. Just tell me your coding philosophy. Just tell me why you wrote the code you did."

"I'll tell you something." Luis rose, teetering. "That manager … paid me so little … hic! … I had to take on three more jobs to make ends meet!" Luis formed a fist. "I had to cut a lot of corners to make it work! So don't you dare come here and tell me how to code!"

Sergio easily ducked under Luis's swinging arm. He grabbed the laptop and ran.

Working for the Weekend

"Any luck with Luis?" Miguel asked the next day.

"Absolutely not. He was uncommunicative, clearly incompetent, and probably drunk on the job. He says you paid him so little he had to take on three more jobs."

"He took three jobs, I think, because he drinks so much," Miguel said. "And we let him go as soon as we found out."

"Well, that's developer two," Sergio said. "Only one more to track down."

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