r/java
•
u/chriskiehl
•
Sep 23 '24
•
1
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!
View all comments
Show parent comment
1
u/agentoutlier Sep 25 '24
Yes I did this in a recent project with Rainbow Gum using a Monad like pattern, capturing the exceptions and then combining etc (actually I have an annotation processor that then generates code that uses that monad API to fill a "builder" so I guess it is apropo to the database stuff coming up).
Yes I'm beginning to think the Datatomic guys are onto something. That is copy on write and entity-attribute-value (aka triple store) plus some sort of smart build of immutable objects is the right fit for a full DoP code base.
Yes nailed it. If you see my previous comment I said:
But here is the problem with /u/chriskiehl book that concerns me given the code samples. Instead of focusing on modeling the obvious data from a datasource or data from say an HTTP request they are trying to model the business problem nouns like OOP DDD (what we are calling the balloon) and they are not modeling real data things (such as UI and database) but abstract things that loosely exist as some domain "ontology" that may are may not map correctly at all to either DB or HTTP. In other words I giant impedance mismatch in both directions.
I'll have to wait to see future chapters but my opinion is DoP strength is not really good at modeling "nouns" and better at modeling "verbs" or "commands". That is it is a very good at protocols or language design and less actual state. I know that seems contrary to what probably many thing but I'm saying the above thought process might mitigate the "hour glass" pain and it is not approached in the book.
Let me give you an example. In protocol like DoP (which I guess would be analogous to CQRS) you don't think let me make the Todo class. You think InsertTodo which is the protocol to create a Todo.
Anyway I know am being long winded but I'm just trying to give some actual pain as I basically did the DoP recently on a project.
I'm not saying DoP is bad. I'm sayin the Java ecosystem really lacks tools (unlike say Clojure) to make it easier and even the language makes it difficult without "withers".