Chapter 14. Data-oriented programming
This chapter covers
- Code as code, and data as data
- Data as data
- Data as code
- Code as data
- Code as data as code
Of primary importance to functional programming languages, and Clojure is no exception, is the relationship between an application’s data elements and the code manipulating it. Some programming languages, in support of their paradigms, view the code/data relationship differently. In this chapter, we’ll talk about the data/code split in some modern languages and the way effective Clojure programs are constructed to blur that line. We’ll discuss how elevating data to the level of information can enable interesting simulation and testing solutions by being explicit about data in terms of time. We’ll touch on some representations of data and dig into the power achieved by having code that is data. But to start, we’ll talk about data on its own terms.
In a typical application, perhaps created in Java, the way we think of data is summarized in the following table:
Product ID |
Product name |
Supplier ID |
Price |
Unit sales |
Total |
---|---|---|---|---|---|
0 | Pumpkin spice | 0 | 0.99 | 400,000 | 396,000.00 |
1 | Dung spice | 1 | 1.99 | null | null |
Another way of viewing this same data is at the level of the definition language used to describe it. For the purpose of illustration, we’ll use a rectangle definition language (RDL) that is a variant of SQL:[1]
1 We ran and tested our SQL code on the SQL Fiddle site at http://sqlfiddle.com.