Archive for November, 2009

Declarative code

Wednesday, November 18th, 2009

While reading david’s article about JUnit’s @Theory, I realized that the power of declarative code is often underestimated. JUnit’s @Theory feature is a kind of declarative-style programming that clearly shows the benefits of this paradigm for testing. It greatly improves code maintainability by clearly separating out the assertions from the data set creational logic. It’s important to realize that not just tests can benefit from declarative-style programming, and here are a few concepts that you might be interested in :

  • The Specification pattern. This pattern can be used in a wide range of situations, from abstracting domain constraints to making complex data driven tests more readable thanks to the “outsourcing” of the test data creational logic out of the testcase.
  • Constraint Oriented Programming
  • DSLs can be used to declaratively specify what you’re interested in, rather than how you want to achieve it
  • SQL, XPath, XSLT are all declarative programming languages that focus on the intent