In the presentation Reduce system complexity with Data-Oriented Programming by Yehonathan Sharvit, he discusses the relevance and benefits of Data-Oriented Programming (DOP) for reducing the complexity of Information Systems. He emphasizes the importance of reducing system complexity, which pertains to the amount of brain resources needed to understand a system, and distinguishes it from computational complexity. Yehonathan believes that DOP, which separates code from data, represents data with generic data structures, treats data as a value, and separates data schema from data representation, can help achieve this goal. He provides examples of systems where DOP is particularly suitable, such as web services, web workers, and front-end applications. The speaker also touches upon the importance of data validation and the limitations of using types for data validation, introducing JSON Schema as a more powerful and flexible solution. Throughout the presentation, Yehonathan emphasizes the importance of reducing accidental complexity in systems using consistent data structures and immutability of data.
Reduce system complexity with Data-Oriented Programming: A comprehensive overview
Understanding system complexity
Two types of complexity
Yehonathan Sharvit begins by distinguishing between two types of complexity in programming: computational complexity and system complexity. Computational complexity concerns the machine resources required to run a program, while system complexity deals with the cognitive resources needed to understand a system. Yehonathan quotes the 1986 book “Structure and Interpretation of Computer Programs”, emphasizing the importance of writing code that is easy for people to read before machines execute it. He argues that DOP can significantly reduce system complexity, especially for information systems that manipulate data, such as web services, web workers, and front-end applications.
Principles of Data-Oriented Programming
Separating Code from Data
The first principle of DOP involves separating code from data. Yehonathan explains that data should exist independently of the code, allowing for greater flexibility and simplicity. In practical terms, this means data can be represented using generic structures like maps or records, which can be manipulated without relying on specific classes or objects.
Representing data with generic data structures
Yehonathan highlights the benefits of using generic data structures to represent data. For example, in JavaScript, data can be stored in string maps instead of custom classes. This approach reduces complexity by eliminating the need for class diagrams and leveraging universal libraries for data manipulation and serialization. By treating data as data, developers gain more flexibility and ease of manipulation, viewing the entire system as a data tree.
Treating data as a value
The third principle focuses on immutability, advocating for treating data as a value that never changes. Instead of mutating data, new versions are created, which simplifies reasoning about the system and reduces bugs. Yehonathan addresses performance concerns by introducing structural sharing in hash maps, where modifications to data structures result in shared nodes between versions, ensuring efficiency.
Separating data schema from data representation
The fourth principle involves separating data schema from data representation. This distinction allows developers to validate data while also creating unvalidated data when necessary. By using schema languages like JSON Schema, developers can describe the expected shape of data and validate it at runtime, preventing silent failures and ensuring data integrity.
Practical applications and examples
Data validation and schema languages
Yehonathan emphasizes the importance of data validation to protect entry points in a program. Without validation, applications may process invalid data, leading to difficult-to-detect errors. JSON Schema, for instance, provides a robust way to validate data against predefined schemas, ensuring only valid data enters the system. This practice reduces system complexity by catching errors early and maintaining data consistency.
Performance optimization with structural sharing
Yehonathan explains how structural sharing can optimize performance when working with immutable data structures. This technique ensures that most nodes in a data structure are shared between versions, making updates efficient. For larger data structures, he recommends using persistent data structures from libraries like Clojure, which are designed to handle immutability efficiently.
Real-world implementation
In his presentation, Yehonathan uses practical examples to illustrate the principles of DOP. He demonstrates how to represent data using generic structures, manipulate it immutably, and validate it using schemas. These examples showcase the simplicity and effectiveness of DOP in reducing system complexity.
Reflections and takeaways
High investment, high reward
Yehonathan acknowledges that adopting DOP requires a learning curve, but the long-term benefits make it a worthwhile investment. By reducing system complexity, DOP can lead to more maintainable, understandable, and robust systems, ultimately enhancing productivity and reducing errors.
Community engagement and resources
Sharvit concludes by expressing gratitude to the audience for their engagement and questions, which resonated with the challenges he discussed. He promises to share additional resources, including links to his books and related literature, to help others implement DOP in their projects.
Final thoughts
Yehonathan Sharvit’s presentation on Data-Oriented Programming provides valuable insights into reducing system complexity. By adopting the principles of DOP — separating code from data, using generic data structures, treating data as immutable values, and separating data schema from representation—developers can create simpler, more maintainable information systems. While the transition to DOP requires an initial investment in learning and adapting new practices, the long-term benefits of reduced complexity and increased system robustness make it a compelling approach for modern software development.