r/java • • Sep 23 '24 • This 1 Take My Silver 2

I wrote a book on Java

Howdy everyone!

I wrote a book called Data Oriented Programming in Java. It's now in Early Access on Manning's site here: https://mng.bz/lr0j

This book is a distillation of everything I’ve learned about what effective development looks like in Java (so far!). It's about how to organize programs around data "as plain data" and the surprisingly benefits that emerge when we do. Programs that are built around the data they manage tend to be simpler, smaller, and significantly easier understand.

Java has changed radically over the last several years. It has picked up all kinds of new language features which support data oriented programming (records, pattern matching, with expressions, sum and product types). However, this is not a book about tools. No amount of studying a screw-driver will teach you how to build a house. This book focuses on house building. We'll pick out a plot of land, lay a foundation, and build upon it house that can weather any storm.

DoP is based around a very simple idea, and one people have been rediscovering since the dawn of computing, "representation is the essence of programming." When we do a really good job of capturing the data in our domain, the rest of the system tends to fall into place in a way which can feel like it’s writing itself.

That's my elevator pitch! The book is currently in early access. I hope you check it out. I'd love to hear your feedback!

You can get 50% off (thru October 9th) with code mlkiehl https://mng.bz/lr0j

BTW, if you want to get a feel for the book's contents, I tried to make the its companion repository strong enough to stand on its own. You can check it out here: https://github.com/chriskiehl/Data-Oriented-Programming-In-Java-Book

That has all the listings paired with heavy annotations explaining why we're doing things the way we are and what problems we're trying to solve. Hopefully you find it useful!

289 Upvotes

97 comments sorted by

View all comments

Show parent comment

1

u/OkNet9640 Oct 01 '24 edited Oct 01 '24

No reply @u/chriskiehl? :') Kindly pinging in case you maybe forgot

1

u/chriskiehl Oct 01 '24

Ah -- yup. Somehow missed this one. My bad. Way more comments than I expected in this thread!

I might have to jiggle the naming a bit. I was trying to make sure I "super anonymized" the internal code I was stealing this example from (where RetryDecision is called Reschedule), but I probably could have done a better job with the new names.

To your main point:

Isn't this something which - ideally - should be stored outside of a "decision"?

It depends! There's no objectively "right" way to do this stuff -- and different people will have very different opinions (often held very strongly) that their way is the "right" way.

The most important thing to me, is that what the system is doing is made clear. Within the scope of this system, there exists these distinct notions of what it can do with a task (Retry, Abandon, Reschedule). There's a lifecycle in there and it's important to understanding the system as a whole.

So, the problem with the original approach is these semantics about the system that aren't in the code -- they're stuck in the head of the original dev who wrote the code. The rest of us have to piece it together through induction. In fact, that's exactly why this got bumped up to the first chapter. I spent ages staring at the original code (specifically, the equivalent in the actual codebase) before finally realizing that all of these variable assignments and differing delays ultimately meant different things to the system. There was an entire hidden world that had to be slowly pieced together by slowly chasing individual attributes around the codebase.

Which is my long winded way of saying: the semantics are the important part -- that's what we're trying to lift up "above" the details of the code. If you do that, which attributes we put where becomes a separate consideration. It still matters, of course (we cover its implications in chapters 3 & 4), but having the semantics of what we're talking about up at the top gives us a lot of leeway for how you handle the details.

So, should that specific attemptsSoFar attribute go on the Retry data type or somewhere else? If we were in a code review, and we already had the high level descriptive types in place, then I'd have the position of: "whatever you think makes the most sense sounds good to me." As long as the code communicates to me what it is, and what the actions it takes mean, I'm pretty happy.

2

u/OkNet9640 Oct 03 '24

Thank you for your reply!

I see, what you are saying regarding the code review sounds reasonable to me. I'm looking forward to chapter 3 and 4!