Fork me on GitHub

Hey! Data oriented programming might be the most valuable idea I've learned working with Clojure, that I've been able to transfer to other languages. DOP has changed how I approach Python, Javascript, Go and Java. Now I'm looking to learn C. My motivation for learning C is: • To learn how computer memory works • To learn how to write programs that use the memory effectively, to achieve better performance then when working with objects • To learn how to work with big datasets • Perhaps even learn some graphics. --- I have an impression that it's possible to apply data oriented programming to C too. It's structs and functions, right? Therefore: Do you have learning resources to recommend when I want to write C with data-orientation in mind? Thanks! 😄

Yehonathan Sharvit15:07:57

@teodorlu Can you share some details about the way you applied DOP in Java? Is it aligned with what I present in the appendix about Java in my book?


I haven't read your appendix. I might have to! In short: 1. Consider just using hash maps and lists instead of "everything is an object" 2. When making classes, make them trivial to convert from/to JSON 3. When making classes, make them small and immutable. Consider using dataclasses.


You're referring to Appendix B?


I've either just used a map, or gone the "reflection" route with Gson or Jackson. I haven't really encountered the need to treat the objects as maps. If I were to do that, I guess I could just convert to Json and then convert to a map. My primary benefit in Java has simply been "less object stuff". Represent a domain entity with an immutable object, done. Don't write setters. Then try to build a "language" for working with those domain objects in a way that makes sense.


C has no objects, no class system, no built-in hash maps or lists, unless you implement them yourself from the constructs that C does provide.


It is certainly possible to write pure functions in C, but in idiomatic C, they are the exception, I would say.