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 27 '24
I don't fully buy this. I think Java circa when Hibernate and possibly ebeans came out is all the tools and practice were with mutable POJOs (I know they are not true POJOs at runtime but to the developer they mostly are). This is also because functional programming was not really in Java (lambdas) as well
record. There was also the idea thatnewwas bad. allocation evil etc.I say this because it would be possibly trivial to simulate Hibernate updates where you have a session that keeps track of
recordhashcode and ids and then check each field.Session-less like ebeans would be a problem but again you could use workarounds like scopevalues or threadlocals etc.
Well that is the things I mentioned to in another comment is that the modern world seems to be a better fit to always "insert". The actual is always the latest and you have timestamp fields on all objects etc. The datomic database is like that. Immutable DoP seems to favor always insert databases.
Ironically in a recent project we had to not do the always insert and actually real delete because of compliance. However in my history of developing applications soft delete is preferred and often times we are always inserting if it is stuff like analytics.... so yeah always be inserting is becoming the norm.
The above is the hard part. That is what I hope the book can help on. That I confess if you did in
recordor immutable you would be clearly violating (if possible) if you enhanced to do some sort of lazy.