February 28, 2009

change the web challenge

The not-for-profit Social Actions just launched the Change the Web Challenge. The idea is to come up with the greatest application you can think of that leverages their API.

Their API allows you to search a database of social actions -- things like volunteering opportunities, fundraising events, petitions -- aggregated from contributors like kiva.org or idealist.org.

For a quick peek at what you have access to, you can try my very own search for opportunities. The code for it is available as a git repository.

November 30, 2008

test-first VS writing a test harness

There is a common understanding that code written using a test-first approach (as in TDD-style) ends up being more maintainable than code that has been harnessed with tests later on. I would justify that understanding as follows:

TDD simplifies original design. This one is easy. By driving the design through small unit tests, we never write code that is unnecessary and experienced TDDers know to make the tests pass with the simplest thing that works. Further, because we gain immediately from writing testable code, the code usually ends up loosely coupled with no implicit dependencies and few explicit dependencies.
Another thing is that by writing the code that exercises the implementation, we design both sides of the API, client code and implementation at the same time. I blogged about client code as design some time ago.

The tests once failed for lack of functionality. To make sure the test is bug-free -- and actually testing the upcoming functionality -- it is imperative to make it fail before making it pass. If you're testing first, that's easy. If you're writing a test harness, you might have to comment out a bit of code to get the red bar, but then will it still compile? Will it still be coherent at runtime? A test harness is forever dubious.

TDD gives you fine-grained coverage. With very little overhead, TDD gives you fine-grained coverage since you're writing the simplest test that brings you forward, all the time. In the words of Gerard Meszaros, this gives you better Defect Localization. When writing a test harness, we usually emphasize the higher level functionality and forget about the smaller 'units' of work. These smaller units might be hard to test because they are implicit, hidden/encapsulated, or even unfathomable.

Test/Specification mismatch. The tests are the requirements for the code. The BDD people have taken this to the next level, but it remains true with TDD. Test code is the most useful documentation to a fellow developer: it's working, up to date, terse, and it serves as an example of client code. When developing TDD-style, the tests become the developers' understanding of the stories -- the ultimate reference.
If writing tests later on, we need to match the functional requirements with the actual codebase, like pieces of a puzzle. Except there will be mismatches, where the developers were not really clear about the requirements. What are we to do then? For this reason alone, test harnessing a big codebase is just really, really hard.

Interestingly, most of the benefits derived from test-first development are gone even if you write the tests right after new code.

October 26, 2008

about free culture

I just finished reading The Future Of Ideas and Free Culture. I read both books avidly and I would recommend them to pretty much anyone -- programmer or not. What's more, they are both available for free online, under a creative commons license.

In both books, Lessig dissects the state and the fate of the commons in american society. The commons are to be cherished and cared for as they lead to innovation, creativity, and a free culture.

The Future Of Ideas is mostly concerned about explaining the concept of commons and the one of layers. The idea of layers is taken from Yochai Benkler and divides the network in three parts: the physical layer, the code, and the content. Lessig then explains how the balance of control at each layer affects innovation and creativity. The example stories include Napster, MP3.com, UNIX, and deCSS.

Free Culture is mostly concerned about the effects of excessive control on culture. Lessig discusses copyright law, intellectual property, and the concentration of the media. The example stories include the infamous RIAA lawsuits and the Eldred v. Ashcroft case.

A few things strike me about this free culture debate:

  • There is no clear stakeholder in the 'new'. The new innovators and creators that free culture helps aren't yet established. This makes the fight incredibly hard to win. It's another case of special interests violating the people.
  • There is no obvious way to disagree with Lessig unless you have a stake in the 'old'. Lessig explains his case rationally and is smart enough to include the whole political spectrum with his arguments.
  • Prolonging the term of existing copyrights is absurd. The objective of copyrights is to give an incentive to innovators. Once the innovation has seen the light of day, prolonging the term of copyrights delays their introduction in the public domain where they could give rise to even more innovation. Thus, prolonging the term of copyrights goes against their prime objective.

As a side note, another book from Lessig just came out: Remix.