Some people just don't like declarative programming

Created 23rd December, 2007 07:51 (UTC), last edited 7th November, 2013 05:01 (UTC)

The declarative style of programming is not to everybody's taste. There are many who simply prefer the overtly operational nature of machine-oriented programs—for them, there is more psychological satisfaction to be had in exercising active control over the 'moving parts' of a computation than there is in the seemingly more passive business of declaring what the computation is to achieve. This preference may persist whatever claims are made or substantiated about the virtues of (present-day) logic programming.

I bet you thought that quote was going to be about functional programming until the last two words?

The quote is from Christopher Hogger's 1990 book Essentials of Logic Programming¹ [1This book was my university text on logic programming at Imperial College and Chris Hogger gave the lectures.]. Although the importance of logic programming has declined over the nearly twenty years since he wrote that passage the difference between declarative and imperative programming and the preference of some for one or the other is very much still with us.

He is right in talking about the fun aspects of programming—this is a big draw for many developers, but not all. I think many who prefer imperative programming simply have more trust in their solutions when they can see the moving parts and can fiddle with them. Getting to see and play with the ballistics of a program makes all sorts of things readily understandable that are hidden in declarative systems.

That doesn't mean that declarative programming isn't fun and it doesn't mean that we shouldn't trust our solutions even though we don't know how the answer is derived. Many of us are very happy to use compilers we barely comprehend, database engines which resolve problems for us that many don't even know exist and languages which abstract away not only the underlying machine but nearly all of the layers above that too.

Given the normal history of these things I think there'll be a resurgence in logic programming interest sometime in the next ten to fifteen years, as seems to be the repeated rise then decline and then rise again of programming paradigms—just look at object orientation and functional programming for two examples.

The decline of logic programming itself is certainly a shame. Logic programming has many useful things to teach us, for example, it allows us to reason about looping constructs and conditionals in a unified manner—something very important in Test Driven Development because it allows us to understand exactly what we get for our tests and how to test more of the program whilst writing fewer tests.