This chapter goes through an example of cleaning up a Java class, JUnit ComparisonCompacter.
Some examples of improvements:
if (expected == null || actual == null || stringsAreEqual()) {
...
to
if (shouldNotCompact()) {
...
bool shouldNotCompact() {
return expected == null || actual == null || stringsAreEqual();
}
String compact() {
...
to
String formatCompactedComparison() {
...
Follow the Boy Scout Rule - always leave code cleaner than you found it.