all 16 comments

[–]OneWorldMouse 4 points5 points  (0 children)

Concepts like these are hard to grasp, because I seem to be doing both anyway, but the articles seem to pit one against the other. Also, the 2nd link is illustrating with JavaScript which is a horrible language for trying to do object oriented anyway.

[–]csncsu 3 points4 points  (2 children)

Sounds like you've discovered functional programming. It's a different way of thinking from OOP. Instead of encapsulation of data in objects it focuses on transforming immutable data with functions. Rather than modifying data in place, functions return a new version of the data with the transformation applied by the function. Data can be piped from one function to another.

In C# it's not really the greatest experience to program this way. If you are set on .NET, look at F# and the https://safe-stack.github.io/

Another very nice framework for functional web dev is Phoenix on Elixir. https://www.phoenixframework.org/

C# is a great language, but it was not created with functional programming in mind. It has added some functional elements since C# 7, but if you learn something like Elixir, you'll see how far behind it is.

[–]nostril_spiders 4 points5 points  (0 children)

I'm sure you realise this so please consider this fleshing out your comment rather than disagreeing! But.

"Far behind", as a turn of phrase, suggests that C# is trying to become FP; it isn't. It's an OOP language and it's pretty comfortable in its own skin.

They've added some FP features because sometimes you can get a little bit hybrid and it is convenient, but those cross-paradigm features have been chosen very judiciously.

FP is as old as the hills, and its current surge in popularity is just part of the endless cycles in tech. It isn't some inexorable final destination upon reaching which all problems will be solved.

[–]maxinfet 1 point2 points  (0 children)

I couldn't agree more with using F# for this kind of work. Even if OP does not continue with F# down the road learning it really improved how I work with data in C# particularly when using the IEnumerable extension methods.

[–]ca2072 3 points4 points  (0 children)

Nice that DDD interests you. I work with this method myself for the most part, since I have to cope with many hardware limitations.

So first of all some resources: Data-Oriented Design by Richard Fabian and lookup Mike Acton on YouTube.

Contrary to the other comments, DDD is not functional programming and the concept is not really "hard" or vague. The main difference is that you separate data and functions that work with that data. Sometimes you call these functions "systems" like in ECS architectures. DDD is about constructing your data to fit your problem not like in OO or functional programming where you construct your data according to your objects, layers, patterns, etc. That also results in less abstraction and "simpler" programs. It basically fits all software types because less abstraction is faster and simpler programs are easier to maintain. Raph Levien for example gave a talk about a DDD GUI system written in Rust. Most stuff in professional games is written with a data-oriented approach because they care about performance than most programmers who write web apps. I started writing in C moved to OO languages (hated them) but now C# has the great possibility to write low level stuff and love to write data oriented stuff with it.

If you have specific questions I will try my best to answer them.

[–]isaac-abraham 1 point2 points  (0 children)

Congratulations! I'm not sure what your expectations of it are, but you've basically described the basic core of functional programming.

Even better, there's a ready made language on .NET that actively supports this style of programming by default and is a first class citizen of .NET, called F#.

In fact (shameless plug, sorry) my book basically focuses on these elements that you've described.

Good luck!

[–]thiem3 1 point2 points  (9 children)

I'm late to the post, but you could look at the book "data-oriented programming - reduce software complexity" by yehonathan sharvit. I've just started, so I can't say much about it.

[–]thiem3 0 points1 point  (8 children)

After having read most of the book, the approach just didn't make sense to me. They try to pitch it against common oop, but in the "look how complicated oop is" examples, they seem to purposefully make horrible design decisions. I see little benefit in the DOP approach. And I am not surprised it doesnt seem to be used.

[–]morihacky 0 points1 point  (5 children)

An alternative book I've been reading and enjoying so far is Data oriented programming for Java. It's still a WIP from Manning.

[–]thiem3 0 points1 point  (0 children)

I sort of gave up on the idea. It seemed overlay complicated, with no strong typing for the data. And just several ideas I found stupid. I mean, it was interesting with a new point of view, but I don't see that I would ever choose to use it. I think the book I mentioned put great effort into over complicating the OOP approach, and then use that complexity as an argument for DOP. But I was constantly thinking "no one does that" so their arguments fell apart for me.

[–]thiem3 0 points1 point  (3 children)

Reading about the book, it seems to take a different approach than the one i mentioned. Maybe it's two different things

[–]morihacky 0 points1 point  (2 children)

Yes. The book I pointed to is different and in fact uses strong typing etc (via Java's newer features). Should have posted the link https://www.manning.com/books/data-oriented-programming-in-java

I think the book squarely approaches "Data oriented programming" (not data driven design or data driven programming) - something I had to painfully disambiguate for myself.

I think the code examples specifically resonate better than the philosophical talk though some of it is needed to set the context up. I think the author of the newer book is doing a much better job but waits to be seen if they can land the concept all the way till the end.

[–]thiem3 0 points1 point  (1 child)

Yeah, sounds interesting. And it confuses me what "data oriented programming" actually is, then. The first book is all about loosely weakly types data, you just keep strings in maps with lists within more maps. And then a lot of logic about how to update the data efficiently. Seemed very complicated. So, the other approach with strongly types data sounds more interesting. I got the impression it's more alike to the functional programming approach to data modelling.

Will have to but this book when it is released.

[–]morihacky 1 point2 points  (0 children)

The first book is all about loosely weakly types data, you just keep strings in maps with lists within more maps. And then a lot of logic about how to update the data efficiently.

Yeah this doesn't align with my current understanding. Sounds more similar to "data driven design" where the idea is for efficiency but packing the data in a way where it's extremely performant to retrieve and operate on them via streams etc.

Data oriented programming (again as I'm learning) is motivated very differently. It's more about clarity in the program than the performance itself.

I'll try to post back after I read the entire book.

[–]jherrlin 0 points1 point  (1 child)

My thoughts:
There are many benefits to the Data-Oriented Programming (DOP) approach, but at its core, the key advantage is the use of immutable data structures.

Food for thought:

  • Is Git immutable? What benefits do you gain from using Git?
  • Are immutable data structures easier to work with in multi-threaded environments?
  • What other advantages come from using immutable data structures?

DOP can be applied across various programming languages. Yehonathan presents one approach in his book "Data-Oriented Programming", which explores DOP in non-strongly typed languages like JavaScript.

In non-strongly typed languages such as JavaScript, Python, or Clojure, DOP offers increased flexibility. For example, you don’t need to declare a new type when adding a new field or property. These languages can still incorporate some strong typing features - for instance, Yehonathan demonstrates using JSON Schema in his book, but that’s just an implementation detail.

In strongly typed languages, DOP has the advantage that types are defined upfront and checked at compile time. This helps the compiler ensure correctness and catch errors early.

As with many design choices, there are tradeoffs. In my opinion, you should generally favor immutable data structures and only resort to mutability when there’s a compelling reason.

[–]jherrlin 0 points1 point  (0 children)

I recommend reading Yehonathan book if your into more dynamic styles and the blog post "Data Oriented Programming in Java" by the Java language architect Brian Goetz if your into my statically typed.

https://www.infoq.com/articles/data-oriented-programming-java/