My very short review of The ThoughtWorks Anthology. The ThoughtWorks Anthology contains 13 essays on software development from different people. The quality of the essays varies widely but in the end: Recommended.

Solving the Business “Last Mile”
Excellent. Worth the book alone. This essay will lead the community to accept that there is a growing last mile problem for companies between the end of development and the going live.
One Lair and Twenty Ruby DSLs
Nothing really new, but an extensive overview over several DSL techniques in Ruby.
The Lush Landscape of Languages
Sub-par. Only interesting if you know nothing about the differences in programming languages. Filler stuff.
Polyglot Programming
Awful. For an explanation see below.
Object Calisthenics
Interesting and thought provoking. Could make you a better developer.
What is an Iteration Manager Anyway?
Good new insights about the general role of Scrum Masters and other Iteration Managers in agile projects.
Project Vital Signs
The team mood chart is genius.
Consumer Driven Contracts: A Service Evolution Pattern
Do your SOA from the consumer side not the provider side, excellent idea.
Domain Annotations
Very good! If your into Domain Driven Design, a must read.
Refactoring Ant Build files
I’ve been developing Ant build files since the beginning of Ant, but still got some insights.
Single-Click Software Release
Some good points for the deployment process, worth reading.
Agile vs. Waterfall Testing for Enterprise Web Apps
Overview of testing methods and how the fit for agile, solid but could have more punch.
Pragmatic Performance Testing
Sorry to the author, I didn’t read this one :-)

Let me illustrate how bad some parts of the book are. One essay with a clear bias against Java wants to establish how awful Java is and how wonderful other JVM languages like Groovy and JRuby are. After a distorted line number example there is an even more distorted isBlank example. For Java the author presents an implementation from Jakarta Commons, a heap of notoriously bad code.

public static boolean isBlank(String str) {
 int strLen;
 if (str == null || (strLen = str.length()) == 0) {
  return true;
 }
 for (int i = 0; i < strLen; i++) {
  if ((Character.isWhitespace(str.charAt(i)) == false)) {
   return false;
  }
 }
 return true;
}

For comparison the JRuby example (which has other performance and memory characteristics) is short

class String
  def blank?
      empty? || strip.empty?
  end
end

One who is moderatly fluent in Java would write the following code though:

  public static boolean isBlank(String string) {
    return isEmpty(string) || (isEmpty(string.trim()));
  }

  public static boolean isEmpty(String string) {
   return null == string || string.length() == 0;
  }

Not as nice and short as the JRuby example, but much better than the ugly Commons example. And with static imports the methods aren’t that ugly to use than before in Java. A isBlank("Hello") works.

But beside some bad essays the book is worth it’s money (Well it is cheap).

Thanks for listening.

Update: Lowell: “If you are using Java 6, there is a new method: String.isEmpty(). You could use that in your Java example and then you wouldn’t need to write your own.” Thanks.


8 Responses to “Book Review of “The ThoughtWorks Anthology: Essays on Software Technology and Innovation””  

  1. Gravatar Icon 1 vr

    I would not be as quick to brand isBlank() as an example of bad code. It’s a static utility method and it is only required to do what it is asked for, but with a maximum possible efficiency. Indeed, the for-loop would look a bit ugly to a stranger, but strangers don’t look inside the code, they would just use it, unless they have the urge to criticize or a sudden curiosity attack.

    See, your suggested “substitute” calls String’s trim, which (a) has TWO loops (to check from the beginning and the end of the String; (b) considers any symbol with a code lass than ‘ ‘ to be a whitespace, which is not what isBlank() doing (it is more strict and sticks to Unicode definition of whitespace). Not only that, a call to your string.trim() results in creation of a new String object, which you’re almost certainly not going to use (unless it _is_ blank and it gets cached by VM in the String pool). Think again: isBlank() does exactly what it was asked for, is more efficient and you don’t have to think about all of the above, unless you’re that wonderful essay author or just a reader with brain somewhat disturbed by essay’s content.

  2. Gravatar Icon 2 stephan

    As I’ve wrote (which has other performance and memory characteristics).

    “[…] results in creation of a new String object, […]”

    I know, see above.

    “[…] , is more efficient […]”

    I know, see above.

  3. Gravatar Icon 3 lumpynose

    To add to what vr said, another thing to think about is that Commons Lang isblank() is a library routine which is probably used a lot; I use it all the time. Its code is clean, simple, and straightforward so it will be easy to maintain. It may not be “pretty” from the perspective of a Ruby programmer, but like vr says, it’s maximally efficient.

    Speed is still a significant issue with Ruby, perhaps because there is too much “pretty” Ruby code that’s inefficient.

  4. Gravatar Icon 4 stephan

    Yes, as I’ve wrote:

    “(which has other performance and memory characteristics).”

    trim() probably does not create a new String in Java, because Strings are immutable (I know Reflection yaddayadda).

  5. Gravatar Icon 5 lumpynose

    “trim() probably does not create a new String in Java” is that a typo? Since Strings are immutable I’d think that the obvious conclusion is that it would have to create a new String.

    And if you look at the source, trim() calls substring(), which ends with

    [pre]
    return ((beginIndex == 0) && (endIndex == count)) ? this :
    new String(offset beginIndex, endIndex - beginIndex, value);
    [/pre]

  6. Gravatar Icon 6 stephan

    Thanks for looking, it does create a new String. What I meant was that it would create a new String object but do not copy and use a new character array but reuse the old one, just with different pointers to beginning and end. Because String is immutable this would work.

  7. Gravatar Icon 7 stephan

    I took a look at new String(), they do a array copy, perhaps because otherwise a larger String from which a substring was created could not be reclaimed by GC.

  8. Gravatar Icon 8 Lowell

    If you are using Java 6, there is a new method: String.isEmpty(). You could use that in your Java example and then you wouldn’t need to write your own.

Leave a Reply



RSS