the blog for developers

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

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.

You can leave a Reply here. Of course, you should follow me on twitter here.

You can share this post!
Do you want to tell others about this article? Use the social bookmark icons to submit this artice to the service of your choice. Thanks.

About the author: Stephan Schmidt has more than 15 years of internet technology experience and 10 years experience in agile. He was head of development, consultant and CTO and is a speaker, author and blog writer. He specializes in organizing and optimizing software development helping companies by increasing productivity with lean software development and agile methodologies. Want to know more? All views are only his own.
Leave a reply.

Comments

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.

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.

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.

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).

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]

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.

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.

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.

basic pooker instructions…

shielded:gasser circumvented!purports:overwriting!esteemed:…

Raman

OMG!

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

(Or use isEmpty if ur string is not null and u under java 6).

That last “isEmpty” (OMG indeed) has the problem of creating an extra String object unnecessarily if the string is already trimmed.

Better:

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

Leave a Reply

What people wrote somewhere else:

Additional comments powered by BackType

Guide to CodeMonkeyism

Over the last 4 years I wrote many articles on this blog. To make it easier for you to find the relevant ones, I've organized them into topics.

Top 10

6 reasons why my VC funded startup did fail

Go Ahead: Next Generation Java Programming Style

Java Interview questions: Write a String Reverser

The dark side of NoSQL

7 Bad Signs not to Work for a Software Company or Startup

Is Java dead?

Scala vs. Clojure

Never, never, never use String in Java

No future for functional programming in 2008 – Scala, F# and Nu

Clojure vs Scala, Part 2

Java Developer

Is Java Dead?

Go Ahead: Next Generation Java Programming Style

Be careful with magical code

All variables in Java must be final

Never, never, never use String in Java

Bending Java: More readable code with methods that do nothing?

NoSQL Guy

NoSQL: The Dawn of Polyglot Persistence

The dark side of NoSQL

Essential storage tradeoff: Simple Reads vs. Simple Writes

Sharding destroys the goals of your relational database

The unholy legacy of databases

Startup/CTO

Development Dream Teams

6 reasons why my VC funded startup did fail

American vs. European style of Software Development

12 Things to Reduce Your Lead Time and Time to Market

The high cost of overhead when working in parallel

Essential storage tradeoff: Simple Reads vs. Simple Writes

Job Seeker

Another Good (Java) Interview Question

7 Bad Signs not to Work for a Software Company or Startup

Java Interview questions: Write a String Reverser (and use Recursion!)

Java Interview questions: Multiple Inheritance

As a Manager: What I value in developers

Top 10 Tips (+1) to Get a Pay Raise

Agilist

What Developers Need to Know About Agile

5 Practices Better to Change in Your Scrum Implementation

Scrum is not about engineering practices

ScrumMaster and ZenMaster: The joke of certification

What is Trans-Scrum?