ArticleS. MichaelFeathers.
MullingNull [add child]

Mulling Null.

1 2 3 4

When Ramon walked into the lab, it was quiet and still; almost as lifeless as a city street on a Sunday morning. But, it wasn't Sunday, it was Monday and the lab wasn't empty. Sally was alone, sitting at the table closest to the door, gazing into a monitor, barely breathing.

"Hey, good weekend, Sally?"

"Uh," said Sally, "yeah."

"I've been thinking about the null thing", said Ramon, "I think it is a good idea but we have to make sure people don't do it in production code."

"Yup," said Sally, "It's a weird message, isn't it? Don't ever do this in production code, but it's okay to do in tests. Too subtle for politicians, good thing we're developers, right?" Sally smiled.

"It worries me, but I think people can handle it", said Ramon. "We've gotten the team used to the Null Object Pattern over the last couple of months. The team is conscious of that problem, and they are going to have to use fakes sometimes anyway, but I think this will eat away at some hard cases. No one can say that it will be too hard to mock all the collaborators of the TransferDomain classes. By the way, can I borrow that legacy code book tonight?"

"Yeah, sure." said Sally. "Um, have you thought about catches? The catches we have for null pointer exception in that contractor code?"

"Huh?", said Ramon.

"Some of our code catches NullPointerException. I wonder if that would make a difference.

"I don't think so. If some catches that exception internally, big deal. It seems like that pass null technique is all about creating an object good enough to run a specific test."

"Yes, it is" said Sally, "that is what the guy says in the book."

"So, here's another idea. What if we create extra constructors, ones that don't take the parameters we are nulling. We could make them package scope and use them only under test."

"We could, Ramon", said Sally, "but how long will it be before someone thinks that is a good constructor, one that they should use?"

"Hmm... yeah, maybe passing the nulls explicitly is a good idea.", said Ramon.

"Yup", said Sally. "We should also try to notice how often this trick works. You know, Ramon, if we have lots of methods we can test by nulling out constructor parameters, I think it could mean that our code base isn't really all that good."

Ramon started to look puzzled. "Really? Well no time to talk about that now. You got the email about the meeting with Aiden?"

"Yes", said Sally. She downed a last gulp of coffee and walked toward the hallway with Ramon.

1 2 3 4


!commentForm