Monday, June 25, 2007

Mock objects

So I'm reading through the documentation for EasyMock, largely on the recommendation of Neal Ford, Jared Richardson, and others at the recently concluded NFJS.

My principal objection to mock objects has been that they tend to test implementation instead of results. And having read through the 2.2 Readme I think my concern is still justified. I see plenty of ways to verify that methods have been called on the mocked object, but I don't see any way to check the mocked object's state. What if the mocked object changes its interface? This guarantees the test breaks. On the other hand, a state-based test would only be looking at the mocked object's resultant state. The only thing that would break the unit test is if the state accessors changed.

I can certainly see where EasyMock would be helpful. But it still doesn't strike me as a cure-all for the unit testing blues.

Saturday, June 23, 2007

Domain Driven Design

NFJS June 23, Venkat Subramaniam

Model needs to focus on the domain, not the implementation. This is a big problem with the way people think about MVC--too many people think model means database or persistence. But that's an implementation issue. Model must also include behavior and even (gasp!) business logic.

I know I'm guilty of sloppy thinking here. A lot of that was driven by J2EE, where no one put any behavior in the entity objects other than persistence. And to this day, even with other frameworks like Struts and Spring, people still think of "session" objects as owning behavior. Which of course defeats the entire purpose of object-oriented design, where behavior is supposed to live with state.

Paraphrase: "Two major problems: framework and design pattern." Both concepts get abused beyond reason.

Software Engineering

Been attending the Salt Lake No Fluff Just Stuff conference. Caught Neal Ford's keynote last night on Polyglot Programming.

Ford's main point is that while the JVM is still a strong platform, the Java programming language itself has peaked. He argues that Java is already being replaced with dynamically-typed languages such as Groovy, Ruby, or even functional languages like Scala and Jaskell.

In the process of digging Java's grave, Ford talks extensively about the difference between software engineering and other types of "hard" engineering. Drawing on a 1992 article by Jack Reeves, he makes the point that all engineering has two phases: design and production. In civil engineering for example, there's an indeterminate period of design followed by actual construction. The outcome of the design phase is a blueprint or a manufacturing plan.

In software, you have the same two phases. The difference of course is that the actual production phase is nothing more than compilation, linking, and deployment. The "design" phase, then, is the process of planning and writing source code.

So what's the major takeaway? For Ford (and me) the most important observation is that since software production is relatively cheap compared to traditional engineering production, and since there are no mathematical models for verifying software (as compared to finite element analysis), testing becomes much much more critical.

Friday, June 1, 2007

Huffington Post vs. Shovelware

Followed a link to Romanesko and found something else there that caught my eye. Steve Johnson, internet critic at the Chicago Tribune, has this to say...

'Many of the Web's news aggregators (Google News, Topix) and even some original news sites have the feel of "shovelware" -- a series of headlines selected and shoveled onto the page by computer algorithm.

'What The Huffington Post does extremely well is select and highlight its stories to appeal to its audience. Even more important than the whiff of progressive politics is the feeling that there is active human intelligence making choices.'

First, what is an "internet critic" and why do I need it?

Second, I suspect this guy's inhaled more than a few whiffs of progressive politics if he doesn't see HuffPo for what it is: a gale of Democratic- and left-biased opinion. Which is fine. But you already had The Nation, The Atlantic, Washington Monthly, Mother Jones, Daily Kos etc. Not to mention the New York Times, Washington Post, and Guardian (and don't forget the Chicago Tribune!).

Google News is a great idea: instead of filtering the news through unavoidably biased humans, set up an algorithm to highlight the most popular stories. It's fundamentally more democratic than anything you'll find at HuffPo or any human-edited news/opinion site. That's not to say that having a human editor is necessarily a bad thing. But if nothing else it's definitely great to have both. The way Mr. Internet Critic talks, he wants his news 100% filtered 24 hours/day.