Data-oriented programming emphasizes treating data as a first-class citizen by separating code from data and using generic data structures.
Adopting data-oriented programming streamlines business logic automation, data manipulation, and unit testing, but faces challenges in tooling and schema documentation.
Deep dives
Principle of Data-Oriented Programming
Data-oriented programming emphasizes treating data as a first-class citizen in applications and is characterized by four main principles. The first principle involves separating code from data to reduce complexity and improve code reuse. The second principle focuses on representing data with generic data structures such as hash maps and lists instead of specific structures. The third principle advocates for treating data as immutable to prevent complexities arising from mutations and provide structural sharing benefits. The fourth principle underlines the importance of separating data schema from data representation to allow runtime data validation and flexible data manipulation.
Impact of Data-Oriented Programming
Adopting data-oriented programming leads to a streamlined focus on business logic by automating tasks like serialization, schema validation, and generating unit tests. It enables developers to work more efficiently by leveraging tools for data manipulation and reducing the need for manual intervention in common data processes. The approach facilitates unit testing with randomly generated data, simplifies data passing processes, and avoids the manual creation of swagger documentation from endpoints. While some challenges exist in tooling for data schema documentation, the overall benefits include enhanced productivity and streamlined data handling.
Challenges in Data-Oriented Programming
Data-oriented programming excels at edge validation tasks in API endpoints where dynamic validation is necessary but faces difficulties in internal functions where static typing offers advantages in tooling support. The need for discipline in schema documentation and the requirement to enforce schema validation within code functions can present challenges. While dynamic programming provides flexibility at the boundaries of programs, static typing excels in structurally managing data within internal function calls, highlighting a trade-off between flexibility and tooling convenience in different programming scenarios.
Application of Data-Oriented Programming
Data-oriented programming principles are versatile and applicable across various languages, with suitability particularly observed in JavaScript and TypeScript environments. JavaScript's natural fit with data manipulation and TypeScript's decoupled type and schema approach align with data-oriented programming concepts. The adoption of data-oriented programming can be gradual and cherry-picked based on specific programming needs, offering developers freedom to integrate principles flexibly into their coding practices. While communities focused on data-oriented programming are yet to be prominent, avenues like blogs and forums enable practitioners to discuss, share insights, and explore the style's implementations.
Jerod is joined by Yehonathan Sharvit, author of Data-Oriented Programming, to discuss the virtues of treating data as a first-class citizen in our applications and the four principles that make it possible.
Changelog++ members save 2 minutes on this episode because they made the ads disappear. Join today!
Sponsors:
Square – Develop on the platform that sellers trust. There is a massive opportunity for developers to support Square sellers by building apps for today’s business needs. Learn more at changelog.com/square to dive into the docs, APIs, SDKs and to create your Square Developer account — tell them Changelog sent you.
Sentry – Working code means happy customers. That’s exactly why teams choose Sentry. From error tracking to performance monitoring, Sentry helps teams see what actually matters, resolve problems quicker, and learn continuously about their applications - from the frontend to the backend. Use the code CHANGELOG and get the team plan free for three months.
Fly.io – The home of Changelog.com — Deploy your apps and databases close to your users. In minutes you can run your Ruby, Go, Node, Deno, Python, or Elixir app (and databases!) all over the world. No ops required. Learn more at fly.io/changelog and check out the speedrun in their docs.