2 Reduce system complexity by separating Code from Data
As we mentioned in Chapter 0, the big insight of Data Oriented Programming (DO) is that we can decrease the complexity of our systems by separating code from data. Indeed, when code is separated from data, our systems are made of two main pieces that can be thought separately: Data entities and Code modules.
This chapter is a deep dive in the first principle of Data Oriented Programming:
Note
Principle #1: Separate code from data in a way that the code resides in functions whose behavior does not depend on data that is somehow encapsulated in the function’s context.
We illustrate the separation between code and data in the context of the Library Management system that we introduced in Chapter 1 and we unveil the benefits that this separation brings to the system:
- The system is simple: it is easy to understand
- The system is flexible: quite often, it requires no design changes to adapt to changing requirements
We show how to:
- Design a system where code and data are separate
- Write code that respects the separation between code and data.
This chapter focuses on the design of the code part of a system where code and data are separate. In Chapter 3, we will focus on the design of the data part of the system. As we progress in the book, we will discover other benefits of separating code from data.