Data-Oriented Programming

Book description

Eliminate the unavoidable complexity of object-oriented designs. The innovative data-oriented programming paradigm makes your systems less complex by making it simpler to access and manipulate data.

In Data-Oriented Programming you will learn how to:

  • Separate code from data
  • Represent data with generic data structures
  • Manipulate data with general-purpose functions
  • Manage state without mutating data
  • Control concurrency in highly scalable systems
  • Write data-oriented unit tests
  • Specify the shape of your data
  • Benefit from polymorphism without objects
  • Debug programs without a debugger

Data-Oriented Programming is a one-of-a-kind guide that introduces the data-oriented paradigm. This groundbreaking approach represents data with generic immutable data structures. It simplifies state management, eases concurrency, and does away with the common problems you’ll find in object-oriented code. The book presents powerful new ideas through conversations, code snippets, and diagrams that help you quickly grok what’s great about DOP. Best of all, the paradigm is language-agnostic—you’ll learn to write DOP code that can be implemented in JavaScript, Ruby, Python, Clojure, and also in traditional OO languages like Java or C#.

About the Technology
Code that combines behavior and data, as is common in object-oriented designs, can introduce almost unmanageable complexity for state management. The Data-oriented programming (DOP) paradigm simplifies state management by holding application data in immutable generic data structures and then performing calculations using non-mutating general-purpose functions. Your applications are free of state-related bugs and your code is easier to understand and maintain.

About the Book
Data-Oriented Programming teaches you to design software using the groundbreaking data-oriented paradigm. You’ll put DOP into action to design data models for business entities and implement a library management system that manages state without data mutation. The numerous diagrams, intuitive mind maps, and a unique conversational approach all help you get your head around these exciting new ideas. Every chapter has a lightbulb moment that will change the way you think about programming.

What's Inside
  • Separate code from data
  • Represent data with generic data structures
  • Manage state without mutating data
  • Control concurrency in highly scalable systems
  • Write data-oriented unit tests
  • Specify the shape of your data


About the Reader
For programmers who have experience with a high-level programming language like JavaScript, Java, Python, C#, Clojure, or Ruby.

About the Author
Yehonathan Sharvit has over twenty years of experience as a software engineer. He blogs, speaks at conferences, and leads Data-oriented programming workshops around the world.

Quotes
Reach the next level of enlightenment…Reduce accidental complexity and raise the level of abstraction.
- From the Foreword by Michael T. Nygard, author of Release It!: Design and Deploy Production-Ready Software

After I saw the examples, I couldn’t unsee it. I didn’t need a new language; I needed to approach programming differently!
- From the Foreword by Ryan Singer, author of Shape Up: Stop Running in Circles and Ship Work that Matters

If you have to deal with data in your code, you should know about DOP!
- Michael Aydinbas, Exxeta

The principles are straightforward and universally applicable.
- Seth MacPherson, QuoteFactory

Publisher resources

View/Submit Errata

Table of contents

  1. inside front cover
  2. Data-Oriented Programming
  3. Copyright
  4. dedication
  5. Brief contents
  6. contents
  7. front matter
    1. forewords
    2. preface
    3. acknowledgments
    4. about this book
      1. Who should read this book?
      2. How this book is organized: A road map
      3. About the code
      4. liveBook discussion forum
    5. about the author
    6. about the cover illustration
    7. dramatis personae
  8. Part 1. Flexibility
  9. 1 Complexity of object-oriented programming
    1. 1.1 OOP design: Classic or classical?
      1. 1.1.1 The design phase
      2. 1.1.2 UML 101
      3. 1.1.3 Explaining each piece of the class diagram
      4. 1.1.4 The implementation phase
    2. 1.2 Sources of complexity
      1. 1.2.1 Many relations between classes
      2. 1.2.2 Unpredictable code behavior
      3. 1.2.3 Not trivial data serialization
      4. 1.2.4 Complex class hierarchies
    3. Summary
  10. 2 Separation between code and data
    1. 2.1 The two parts of a DOP system
    2. 2.2 Data entities
    3. 2.3 Code modules
    4. 2.4 DOP systems are easy to understand
    5. 2.5 DOP systems are flexible
    6. Summary
  11. 3 Basic data manipulation
    1. 3.1 Designing a data model
    2. 3.2 Representing records as maps
    3. 3.3 Manipulating data with generic functions
    4. 3.4 Calculating search results
    5. 3.5 Handling records of different types
    6. Summary
  12. 4 State management
    1. 4.1 Multiple versions of the system data
    2. 4.2 Structural sharing
    3. 4.3 Implementing structural sharing
    4. 4.4 Data safety
    5. 4.5 The commit phase of a mutation
    6. 4.6 Ensuring system state integrity
    7. 4.7 Restoring previous states
    8. Summary
  13. 5 Basic concurrency control
    1. 5.1 Optimistic concurrency control
    2. 5.2 Reconciliation between concurrent mutations
    3. 5.3 Reducing collections
    4. 5.4 Structural difference
    5. 5.5 Implementing the reconciliation algorithm
    6. Summary
  14. 6 Unit tests
    1. 6.1 The simplicity of data-oriented test cases
    2. 6.2 Unit tests for data manipulation code
      1. 6.2.1 The tree of function calls
      2. 6.2.2 Unit tests for functions down the tree
      3. 6.2.3 Unit tests for nodes in the tree
    3. 6.3 Unit tests for queries
    4. 6.4 Unit tests for mutations
    5. Moving forward
    6. Summary
  15. Part 2. Scalability
  16. 7 Basic data validation
    1. 7.1 Data validation in DOP
    2. 7.2 JSON Schema in a nutshell
    3. 7.3 Schema flexibility and strictness
    4. 7.4 Schema composition
    5. 7.5 Details about data validation failures
    6. Summary
  17. 8 Advanced concurrency control
    1. 8.1 The complexity of locks
    2. 8.2 Thread-safe counter with atoms
    3. 8.3 Thread-safe cache with atoms
    4. 8.4 State management with atoms
    5. Summary
  18. 9 Persistent data structures
    1. 9.1 The need for persistent data structures
    2. 9.2 The efficiency of persistent data structures
    3. 9.3 Persistent data structures libraries
      1. 9.3.1 Persistent data structures in Java
      2. 9.3.2 Persistent data structures in JavaScript
    4. 9.4 Persistent data structures in action
      1. 9.4.1 Writing queries with persistent data structures
      2. 9.4.2 Writing mutations with persistent data structures
      3. 9.4.3 Serialization and deserialization
      4. 9.4.4 Structural diff
    5. Summary
  19. 10 Database operations
    1. 10.1 Fetching data from the database
    2. 10.2 Storing data in the database
    3. 10.3 Simple data manipulation
    4. 10.4 Advanced data manipulation
    5. Summary
  20. 11 Web services
    1. 11.1 Another feature request
    2. 11.2 Building the insides like the outsides
    3. 11.3 Representing a client request as a map
    4. 11.4 Representing a server response as a map
    5. 11.5 Passing information forward
    6. 11.6 Search result enrichment in action
    7. Delivering on time
    8. Summary
  21. Part 3. Maintainability
  22. 12 Advanced data validation
    1. 12.1 Function arguments validation
    2. 12.2 Return value validation
    3. 12.3 Advanced data validation
    4. 12.4 Automatic generation of data model diagrams
    5. 12.5 Automatic generation of schema-based unit tests
    6. 12.6 A new gift
    7. Summary
  23. 13 Polymorphism
    1. 13.1 The essence of polymorphism
    2. 13.2 Multimethods with single dispatch
    3. 13.3 Multimethods with multiple dispatch
    4. 13.4 Multimethods with dynamic dispatch
    5. 13.5 Integrating multimethods in a production system
    6. Summary
  24. 14 Advanced data manipulation
    1. 14.1 Updating a value in a map with eloquence
    2. 14.2 Manipulating nested data
    3. 14.3 Using the best tool for the job
    4. 14.4 Unwinding at ease
    5. Summary
  25. 15 Debugging
    1. 15.1 Determinism in programming
    2. 15.2 Reproducibility with numbers and strings
    3. 15.3 Reproducibility with any data
    4. 15.4 Unit tests
    5. 15.5 Dealing with external data sources
    6. Farewell
    7. Summary
  26. Appendix A. Principles of data-oriented programming
    1. A.1 Principle #1: Separate code from data
      1. A.1.1 Illustration of Principle #1
      2. A.1.2 Benefits of Principle #1
      3. A.1.3 Cost for Principle #1
      4. A.1.4 Summary of Principle #1
    2. A.2 Principle #2: Represent data with generic data structures
      1. A.2.1 Illustration of Principle #2
      2. A.2.2 Benefits of Principle #2
      3. A.2.3 Cost for Principle #2
      4. A.2.4 Summary of Principle #2
    3. A.3 Principle #3: Data is immutable
      1. A.3.1 Illustration of Principle #3
      2. A.3.2 Benefits of Principle #3
      3. A.3.3 Cost for Principle #3
      4. A.3.4 Summary of Principle #3
    4. A.4 Principle #4: Separate data schema from data representation
      1. A.4.1 Illustration of Principle #4
      2. A.4.2 Benefits of Principle #4
      3. A.4.3 Cost for Principle #4
      4. A.4.4 Summary of Principle #4
    5. Conclusion
  27. Appendix B. Generic data access in statically-typed languages
    1. B.1 Dynamic getters for string maps
      1. B.1.1 Accessing non-nested map fields with dynamic getters
      2. B.1.2 Accessing nested map fields with dynamic getters
    2. B.2 Value getters for maps
      1. B.2.1 Accessing non-nested map fields with value getters
      2. B.2.2 Accessing nested map fields with value getters
    3. B.3 Typed getters for maps
      1. B.3.1 Accessing non-nested map fields with typed getters
      2. B.3.2 Accessing nested map fields with typed getters
    4. B.4 Generic access to class members
      1. B.4.1 Generic access to non-nested class members
      2. B.4.2 Generic access to nested class members
      3. B.4.3 Automatic JSON serialization of objects
    5. Summary
  28. Appendix C. Data-oriented programming: A link in the chain of programming paradigms
    1. C.1 Time line
      1. C.1.1 1958: Lisp
      2. C.1.2 1981: Values and objects
      3. C.1.3 2000: Ideal hash trees
      4. C.1.4 2006: Out of the Tar Pit
      5. C.1.5 2007: Clojure
      6. C.1.6 2009: Immutability for all
    2. C.2 DOP principles as best practices
      1. C.2.1 Principle #1: Separate code from data
      2. C.2.2 Principle #2: Represent data with generic data structures
      3. C.2.3 Principle #3: Data is immutable
      4. C.2.4 Principle #4: Separate data schema from data representation
    3. C.3 DOP and other data-related paradigms
      1. C.3.1 Data-oriented design
      2. C.3.2 Data-driven programming
      3. C.3.3 Data-oriented programming (DOP)
    4. Summary
  29. Appendix D. Lodash reference
  30. index
  31. inside back cover

Product information

  • Title: Data-Oriented Programming
  • Author(s): Yehonathan Sharvit
  • Release date: August 2022
  • Publisher(s): Manning Publications
  • ISBN: 9781617298578