data-oriented-programming

teodorlu 2022-07-14T14:39:42.604599Z

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! 😄

teodorlu 2022-07-14T14:40:13.513629Z

I'm considering https://www.goodreads.com/en/book/show/13136685-learn-c-the-hard-way by Zed Shaw.

Yehonathan Sharvit 2022-07-14T15:02:57.402779Z

@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?

teodorlu 2022-07-14T15:06:25.606309Z

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.

teodorlu 2022-07-14T15:10:08.511799Z

You're referring to Appendix B?

teodorlu 2022-07-14T15:18:57.401929Z

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.

2022-07-14T19:30:27.813619Z

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.

2022-07-14T19:30:53.717489Z

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

Yehonathan Sharvit 2022-07-17T14:47:54.084779Z

Thank you @teodorlu

👍 1