Speaker Deck

Hello, declarative world

by Tom Stuart

Published August 10, 2015 in Programming

We know that a computer is an imperative machine: a CPU reads one instruction after another, and performs one operation after another, with each operation modifying the state of its registers and memory. But that doesn’t mean we HAVE to write our computer programs as imperative step-by-step recipes; there are other interesting ways to specify a computation.

Ruby’s billed as a “multi-paradigm” language, but, let’s face it, we use it to write imperative object-oriented programs. I'm interested in different ways of programming computers, because I reckon imperative programs are far too low-level and overspecified, which is why as a species we're generally terrible at writing them.

One interesting alternative is declarative programming, where we tell the computer about the problem we want to solve instead of exactly what steps to take to solve it. That idea’s been around for a long time but has recently begun to reappear everywhere.

In this talk I want to encourage you to think outside of your normal programming habits; I’ll present a more abstract and declarative style called relational programming, and show you how to implement a minimal relational language in Ruby. (Dog whistle: this is μKanren.)

Given at Joy of Coding 2015 (http://lanyrd.com/2015/joyofcoding/) and the London Ruby User Group (http://lrug.org/meetings/2015/august/). A video and expanded transcript are available at http://codon.com/hello-declarative-world, and the code is available at http://github.com/tomstuart/kanren.

Other Presentations by this Speaker