r/C_Programming • • Jul 03 '26

Data Oriented Programming

I started reading Data Oriented Programming by Chris Kiehl and something about the book got me really hooked. Maybe it's the way of writing, or the fact that I'm encountering this for the first time or the fact that he used only records and sealed interfaces (Java) to model every code.

I really like his approach and was imagining how I could use same ideas say with structs and enums for instance in Rust or a similar language from a data oriented perspective. However, I wonder if this approach is scalable and can be used as a pattern in all aspects or if there are caveats.

Anyone with more experience on this paradigm or approach to programming?

27 Upvotes

14 comments sorted by

7

u/Online_Matter Jul 03 '26

I know the unity game engine has built a framework around the concept in case that's of interest

https://unity.com/ecs

2

u/Feisty-Assignment393 Jul 03 '26

Oh I didn't know they were the same concept. Good to know.

4

u/Beish Jul 03 '26

I don't know it's going to be anything new since you have a whole book on the subject, but the art of unix programming has the rule of representation and a chapter on data driven programming.

2

u/Feisty-Assignment393 Jul 03 '26

Really cool. I just glanced at the chapter. Probably gonna be my next read.

4

u/8d8n4mbo28026ulk Jul 03 '26

Relatedly, Rob Pike's "Programming with data" is also a great read! Although, DOD is mostly about optimizing how you encode/represent your data and utilising modern processors more effectively.

4

u/SAtchley0 Jul 03 '26

First time hearing about Data Oriented Programming. What is it? How does that compare to Data Oriented Design?

4

u/Feisty-Assignment393 Jul 03 '26

I would think they mean the same 

1

u/cdb_11 Jul 03 '26 edited Jul 03 '26

Nope, it's a separate thing.

Not sure if any clear definition of "data-oriented design" exists, but it's about changing the format of your data to make the necessary transformations efficient. And the mindset is that all of it has to serve real and concrete goals of your program. In the most literal sense of it, just a program transforming data, to solve some specific problem.

In comparison, in OOP (and particularly SOLID principles) you would probably start with modelling the data with classes (likely in a way that reflects the real world somehow), and then write code that wrangles those objects into doing whatever the program actually had to do in the first place. One could argue it's for the sake of readability, but there is no concrete goal for the actual program itself that warrants doing it this way.

edit: for whoever downvoted me, I thought my description of DOD was pretty accurate, albeit maybe still not immediately obvious, because it is a radically different way of thinking from what people are used to. So I am genuinely curious what is the objection here.

3

u/Yamoyek Jul 03 '26

I think you were downvoted because you may have been mistaken about the comment thread. The first comment in the thread is about Data-Oriented Programming vs Data-Oriented Design, which afaik refer to the same thing

1

u/cdb_11 Jul 04 '26

They are definitely not the same thing. Reading the book description from the OP, it does not sound like DOD at all. Side-effects? Immutable data structures?

2

u/timrprobocom Jul 05 '26

For me, I try to organize my applications so I have a big static data structure that has all the control information, so the executable code essentially becomes an interpreter. That way, once it's working for one line, it's usually working for all of them, and changes only have to be made in one place.

I consider that a data-oriented approach.

1

u/Feisty-Assignment393 Jul 05 '26

Yea exactly what he did in chap 8, creating rules and an interpreter. Still tryna wrap my head around it though.