Skip navigation.

Literate Programming in Practice

FIT/FitNesse | programming

I've been secretly working on something... well, it's not that much of a secret... It's a new Fit Fixture for Given/When/Then acceptance tests (or BDD style tests). Andy Palmer and I have been writing it in what spare time we have...

Part of it involves finding classes (potentially written by someone else), instantiating them and returning them for use... Today we took the class that does that and refactored it to death... until it looked like this.

See if you can understand what it's doing...

Some of the highlights include:

	private String camelCaseEquivalentOf(String thisPhrase) {
		String className=EMPTY_STRING;

		String[] wordsInPhrase = separateWordsFrom(thisPhrase);
		for (String word : wordsInPhrase) {
			className = className + properNounFor(word);
		}
		
		return className;
	}

And the pièce de résistance...


	public IRestoreACheckpoint howDoIRestore(String thisCheckpoint) {
		return aNewInstanceOf(aClassThatWill(RESTORE, thisCheckpoint));
	}

	public IPerformAnAction howDoIPerform(String thisAction) {		
		return aNewInstanceOf(aClassThatWill(PERFORM, thisAction));
	}
	
	public IAnswerAQuestion howDoIAsk(String thisQuestion) {
		return aNewInstanceOf(aClassThatWill(ANSWER, thisQuestion));
	}

See the code in context here.

Now that was fun!