Data-Oriented programming
The secret 🍝 sauce 🍝 that makes Clojure systems less complex

February 15, 2021
Yehonathan Sharvit viebel
Data-Oriented programming
The secret 🍝 sauce 🍝 that makes Clojure systems less complex
February 15, 2021
Yehonathan Sharvit viebel
💻 Developer since 2001 (Clojure since 2012)
🎁️Maintainer of Klipse
📖 Author of Data-Oriented programming
📝 Blogger at blog.klipse.tech
🍝 Secret sauce
An element, quality, ability, or practice that makes something or someone successful or distinctive.
Merriam-Webster dictionary
😰Complexity
What makes large systems hard to understand.
Out of the Tar Pit (2006)
1936 👉 λ-calculus (Alonzo Church)
1958 👉 LISP (John McCarthy)
2000 👉 Ideal Hash trees (Phil Bagwell)
2007 👉 Clojure (Rich Hickey)
2006 👉 Out of the Tar Pit (Ben Moseley and Peter Marks)
2021? 👉 Wikipedia article about Data-Oriented programming (Help wanted)
Data-Oriented Computing with symbolic expressions | Functional Programming Composition of functions |
Homoiconicity Representation of LISP programs as LISP data | The REPL? The function |
History of Lisp, John McCarthy 1979
Data is a first class citizen ✈️
Separate code from data
Represent data with generic data structures
Do not mutate data
Language agnostic
OO and FP
Statically or dynamically typed
Applicable in isolation
Powerful when combined
🕸️What makes this system complex?
Nodes with many edges
Many kind of arrows
Association
Composition
Inheritance
Usage
function createAuthor(firstName,
lastName) {
return {
fullName: function() {
return firstName + " " + lastName;
}
};
}
class AuthorData {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
}
class NameCalculation {
static fullName(data) {
return data.firstName + " "
+ data.lastName;
}
}
☕What makes this system less complex?
Separation of concerns
Code diagram constraints
Stateless (static)
Only usage relation
Data diagram constraints
Only association and composition
class Book {
isbn; title;
constructor(publicationYear, title) {
this.publicationYear = publicationYear;
this.title = title;
}
}
var watchmenBook = new Book("978-1779501127",
"Watchmen");
var watchmenBook = new Map([
["publicationYear", 1986],
["title", "Watchmen"]
]);
👎 👎 👎
👍 👍 👍
☕What makes this system less complex?
Weak dependency between code and data
Flexible data model
Generic data manipulation functions
Information path (e.g. ["catalog", "authorsById", "alan-moore", "name"]
)
Display data on console
Serialization for free
Reflection for free
Mutation is bad!
What we need:
Efficient persistent data structures
Atoms
Parse JSON into a map
Manipulate "untyped" primitives
Database driver that works with maps
Separate Code from Data
Represent Data with generic data structures
Do not mutate data
🤑 50% discount: mlsharvit2
Wikipedia article: Data-Oriented programming
#data-oriented-programming on Clojurians