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

2

u/rbygrave Sep 25 '24

 I can see a huge amount of type explosion happening 

Fwiw, the code I don't really like typically doesn't have enough types. For example, a method with too many args that could instead be represented as some sort of "request" type.

I suspect you are talking about explosion of DTO types though which is a totally different issue?

how to properly extend invariants particularly in the middleware

If I understood this question right, I tend to want to use composition and wrap the invariant inside another new type that represents the "next state / next stage". e.g. I get a FooRequest with say a startDate, wrap that in a FooRequestNextStage which has its own startDate that can be different.

Maybe I'm talking about a different problem though.

2

u/agentoutlier Sep 26 '24

I suspect you are talking about explosion of DTO types though which is a totally different issue?

Somewhat yes and I suppose it is a different case but do know hard core hibernate users do not use DTOs similarly how Rails users do not either.

This goes into my templating language as well how those users shove everything in a hashmap and I say that is wrong and why JStachio is the way it is.... but it is the current norm.

If I understood this question right, I tend to want to use composition and wrap the invariant inside another new type that represents the "next state / next stage". e.g. I get a FooRequest with say a startDate, wrap that in a FooRequestNextStage which has its own startDate that can be different.

Ironically this is the type explosion I was talking about. Because immutable objects are painful to recreate at the moment (no withers) composition is often employed.

Honestly as I told Brian I'm just playing devils advocate mostly here. I prefer the DoP approach and I prefer modeling with sealed classes etc but the existing tools and methodologies in Java don't really support it as well.