Data-Oriented programming
The secret ๐ sauce ๐ that makes Clojure systems less complex
Yehonathan Sharvit viebel
Data-Oriented programming
The secret ๐ sauce ๐ that makes Clojure systems less complex
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)
1981 ๐ Values and Objects in Programming Languages (Bruce MacLennan)
2000 ๐ Ideal Hash trees (Phil Bagwell)
2006 ๐ Out of the Tar Pit (Ben Moseley and Peter Marks)
2007 ๐ Clojure (Rich Hickey)
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
Loose coupling between components
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!
Separate Code from Data
Represent Data with generic data structures
Do not mutate data
Wikipedia article: Data-Oriented programming
#data-oriented-programming on Clojurians