Code and Data are One

Posted by Daniel Lyons Mon, 05 May 2008 12:09:00 GMT

There is a general desire to keep code and data separate, but they are indivisible.

We use migrations in Rails to manage changes to the database, but some data is invariably essential to the proper working of the application. The database schema itself is data. As your understanding of the dataset of the application changes so does the database schema; data affecting data.

The code itself is utterly meaningless except as transformations to the data. Even esoteric languages like Haskell, J and Forth which do their best to avoid naming the data work only by computing with it. Nothing else happens other than examining and modifying data. Thus, much data is inline in the code: initial values, special values, error values.

Sometimes it feels like there is a hard distinction between data and code, but even then, it is an illusion. On the processor, there are just bytes; there’s no difference between moving bytes from your code into the registers to examine them or moving data from a file into registers to execute them. It’s all just bytes moving from point A to point B.

The source code itself is probably the most obsessively well-managed data on the planet. Nobody uses version control for anything else.

Consider TeX. Is it a document (data) or a transformation (program)? Both. Restricting your output to DVI or PDF is no different from restricting your output to plain text. You can perform arbitrary computation with TeX. And this is of course necessary to make a well-crafted document: code is needed to compute how to style the data properly.

On the web we try very hard to maintain a separation of “content” and “presentation,” but the CSS is served by the same web server that sends out the HTML. More and more people are using the same template systems to generate their CSS as to generate their HTML: CSS isn’t enough on its own. Of course it isn’t, no amount of built-in functionality can ever replace arbitrary code (until you become Turing-complete or close to it). Even then, you use inline styles and generate not particularly flexible HTML interfaces.

There is no real distinction between content and presentation either. These things are all the same. Data. Or code.

Be aware of the illusion you operate under for the sake of good style.

Tags ,  | 1 comment

Comments

  1. Avatar Danny said about 7 hours later:

    Good point. I had a great argument with my advisor when I first got here about how they are synonymous.

(leave url/email »)

   Comment Markup Help Preview comment