Lurker News
https://www.manning.com/books/data-oriented-programming-in-j...

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://www.manning.com/books/data-oriented-programming-in-j...

Comments (168) 39 threads

raju2 replies#
Let me start by saying (as someone who has written a few technical books of his own)—Congratulations!

I am sure you (assuming this is your first book) are learning that this is a labor of love, and I wish you the very best in this endeavor. You should be proud!
I was exposed to "data oriented programming" thanks to Clojure—wherein maps/sets are the constructs used to pass data (as plain data) around, with simple functions that work with the data, as opposed to the traditional OO (hello ORM) that mangles data to fit some weird hierarchy.
Java's recent innovations certainly make this a lot easier, and I am glad someone is looking at propagating a much needed message.
I will take a look at the book, but I wish you the very best.

mrbonner4 replies#
I am also very interested in how this work in practice. With OOP at least you know the shape of your data structure as opposed to the hash map as a mere container type.
akavi2 replies#
You can get strongly typed "shaped" data without objects[0], even in Java: Records[1].

~Unfortunately, I believe they're mutable (and cannot be made immutable).~ Edit: I was wrong, they're immutable.
[0]: I'm using "object" to mean "data bound to methods", since the concept of aggregate data in general long pre-date OOP (eg, C's structs)
[1]: https://docs.oracle.com/en/java/javase/17/language/records.h...

bedatadriven#
A record's fields are final, so records are immutable (though they can include immutable pointers to mutable objects)
taftster8 replies#
Java Records are immutable (by the most common definition). They don't have any means to update the record (via setters, etc.) after construction. That doesn't mean, for example, you can't store a reference to a mutable type (for example, a List or Map) in your record.

The frustration I have with Records is there is no good way to prevent direct construction of them. That is, the constructor is public, which prevents an easy way of enforcing an invariant during construction.
For example, let's say that you have a record with a Date type. There's no good way to prevent a user from creating the record with an invalid date, one that is out of a needed date range. Or maybe enforcing a field cannot be null or some combination of fields must meet requirements as a group.
The benefit I get from the classic Builder pattern is defeated with Records. I can't enforce checking of my fields before the construction of the record object itself. Presumably I would need to verify the object after construction, which is unfortunate.

Continue this thread — 8 replies

geophile10 replies#
I am an OOP programmer going back to the late 80s (including the cfront days of C++), and a serious user of Python since 2007.

In Python, I sometimes try data-oriented programming, using lists and dicts to structure data. And I find that it does not work well. Once I get two or more levels of nesting, I find it far too easy to get confused about which level I'm on, which is not helped by Python's lack of strong typing. In these situations, I often introduce objects that wrap the map or dict, and have methods that make sense for that level. In other words, the objects can be viewed as providing clear documentation for the whole nested structure, and how it can be navigated.

goostavos32 replies#
>Once I get two or more levels of nesting, I find it far too easy to get confused about which level I'm on

Author here, I agree with you. I have the working memory of a small pigeon.
The flavor of data orientation we cover in the book leverages strongly typed representations of data (as opposed to using hash maps everywhere). So you'll always know what's shape it's in (and the compiler enforces it!). We spend a lot of time exploring the role that the type system can play in our programming and how we represent data.

Continue this thread — 32 replies

FpUser#
>"In these situations, I often introduce objects that wrap the map or dict, and have methods that make sense for that level."

I've been doing the same thing since the end of the 80s as well starting with Turbo/Borland Pascal, C++, and later any other language that supports OOP.

sodapopcan13 replies#
Python's not really built for that AFAIK, though. In languages built for it, you can type your dicts/hashes/maps/whatever and its easier to see what they are/know where the functions that operate on them live. I'm most familiar with Elixir which has structs which are simply specialized map (analogous to dict in Python) where their "type" is the name of the module they belong to. There can only be one struct per module, In this sense is easy to know exactly where its functions live and is almost like a class with the very key difference that modules are not stateful.

Continue this thread — 13 replies

mejutoco#
I recommend you use pydantic for type annotations. Alternatively, dataclasses. Then you pair it with typeguards @typechecked annotation and the types will be checked at runtime for each method/function. You can use mypy to check it at "compile time".

Having clear data types without oop is possible, even in python.

js213 replies#
> Python's lack of strong typing

I see people conflate strong/weak and static/dynamic quite often. Python is strong[1]/dynamic, with optional static typing through annotations and a type checker (mypy, pyright, etc).
Perhaps the easiest way to add static types to data is with pydantic. Here's an example of using pydantic to type-check data provided via an external yaml configuration file:
https://news.ycombinator.com/item?id=41508243
[1] strong/weak are not strictly defined, as compared to dynamic/static, but Python is absolutely on the strong end of the scale. You'll get a runtime TypeError if you try to add a number to a string, for example, compared to say JavaScript which will happily provide a typically meaningless "wat?"-style result.

Continue this thread — 13 replies

ederamen#
Use Data Classes
cbsmith#
Living this dream in Python right now (inherited a code base that used nasty nesting of lists & dicts). You don't strictly need to do OOP to solve the problem, but it really does help to have a data model. Using dataclasses to map out the data structures makes the code so much more readible, and the support for type hints in Python is good enough that you can even debug problems with the type system.
chipdart2 replies#
> (...) by Python's lack of strong typing. In these situations, I often (...)

Python does support strong typing, albeit optional, with type annotations and tools like mypy.
If a problem is caused by the lack of strong typing, why not use strong typing?

Continue this thread — 2 replies

ninetyninenine#
Python now has type hints which can be used with an external type checker in the IDE. You'd probably type it with a class.
clepto#
I see a lot of people mentioning Pydantic here, but you should take a look into TypedDict. It provides a type structure ontop of a plain dictionary, and sounds like exactly what you’d want, and is a built-in that you don’t need a dependency for.

Mypy for example can also see the types of the dictionary are supposed to be when you use it just like a normal dictionary.

kccqzy#
Clojure has spec. That allows you to know a specification of what the data structure contains.
davedx#
With TypeScript you have types to tell you the shape of your data.
goostavos1 reply#
Thanks for the kind words :)

>learning that this is a labor of love
I underestimated both the amount of labor and the amount of love that would be involved. There were more than a few "throw everything out and start over" events along the way to this milestone.
Clojure definitely had a huge impact on how I think about software. Similarly, Haskell and Idris have rearranged my brain. However, I still let Java be Java. The humble object is really tough to beat for managing many kinds of runtime concerns. The book advocates for strongly typed data and leveraging the type system as a tool for thinking.
>Java's recent innovations certainly make this a lot easier
Yeah, it's an exciting time! Java has evolved so much. Algebraic types, pattern matching, `with` expressions -- all kinds of goodies for dealing with data.

jwr#
> Clojure definitely had a huge impact on how I think about software

I could be called a "Clojure programmer", because I make a living from an app written Clojure and ClojureScript. While I always appreciated the incredible JVM, I always looked at Java the language with disgust and contempt, interfacing with it only as was necessary, but recent work on Java makes it much more attractive. I was impressed by the functional interfaces, modern design with mostly static methods, JSR-310 (date and time) is absolutely great — overall, Java has improved a lot over the years.
It has come to the point where I gasp might consider writing some Java code :-)

topspin2 replies#
How have you dealt with the current situation in Java where several new and important language features are still "preview" and are subject to being withdrawn? The possibility that these features might ultimately disappear is not theoretical: String Templates has been removed[1] from 23 as what would have been the "third preview," for example.

The (likely debatable) list of features in 23 that a.) remain preview/incubator and b.) appear relevant to a work on data oriented Java programming are:

    Primitive Types in Patterns, instanceof, and switch (Preview) – JEP 455
    Implicitly Declared Classes and Instance Main Methods (Third Preview) – JEP 477
    Flexible Constructor Bodies (Second Preview) – JEP 482
    Vector API (Eighth Incubator) - JEP 469
    Scoped Values (Third Preview) – JEP 481
[1] https://mail.openjdk.org/pipermail/amber-spec-experts/2024-A... "So, to be clear: there will be no string template feature, even with --enable-preview, in JDK 23." - Gavin Bierman
goostavos1 reply#
I've thought a lot about this quite a bit. In my day to day life, which is a cog in the machine at $Megacorp, I regularly work on embarrassingly old versions of Java (hello JDK 8!). So, not having the latest and greatest language features is a topic close to my heart. As such, the book takes a very tool agnostic approach. If we cover something that's only available advanced JDKs, we also cover what to do if you don't have it.

Data oriented programming is about building around the data in your domain. The latest tools are nice, but they're just tools.

topspin#
I appreciate your conundrum. While it has been good to see Java language designers attempt to advance the language, they've been extremely conservative and non-committal. This is a problem because tooling is costly to develop and tool developers are forever facing the problem of whether to invest the work needed to integrate these language features when they take years to be realized, and may yet vanish. Likewise for authors, such as yourself.
whartung1 reply#
I can't say I'm completely on top of the Java world, but I think the String Templates are one of the very few preview features that have been actually withdrawn and removed, right? Are there others?

I know some drift a bit on their implementations over time, but have not be wholesale yanked out.
Obviously the solution to this is to not rely on these preview functions for production code. The way to do that is to run production in an LTS version of Java. I don't think that's an extreme point of view, frankly.
The new stuff is interesting and cool, and in time, it ends up in the LTS version.
Having lived through Java 5, 6, and 8, these are halcyon times for Java. It's moving VERY fast, and has been for some time.
Are there preview capabilities in the LTS versions? Yes, there are. But they're not under the LTS tent. Don't use them. The demarcation between the development releases and the LTS releases are a smart program to get features out into the world, and set some real lines in the sand for advancement. It helps keep preview items from staying in preview mode for an indeterminate amount of time.
And the two year LTS release cycle for a notoriously conservative eco-system is ample.

topspin3 replies#
> Are there others?

String Literals (JEP 326) made it to preview and got pulled.
> I don't think that's an extreme point of view, frankly.
Can't see where I suggested otherwise. I just wondered how the author was handling all the "in-flight" (An OpenJDK term there, not mine) features that Java currently has outstanding.
> It's moving VERY fast, and has been for some time.
They've been fast at creating new preview features. Actually landing finalized features though? In my view they're taking too long. When I compare Java and Python in this respect -- and I do as a working programmer in both on a frequent basis -- Java is still slow.

perrylaj#
> When I compare Java and Python in this respect -- and I do as a working programmer in both on a frequent basis -- Java is still slow.

I feel this as well, but I also think it's desirable. Java is slower to add features because the bar is quite a bit higher (especially with regard to backwards-compatibility).
I'd much rather have long previews and occasional removal of previews than have a language that becomes bloated and kneecapped by past rushed decisions.
There's Kotlin, Scala, Groovy, etc, if you want to run on the JVM with languages that offer more features (and footguns). I find the balance OK, personally.
I'd much rather them pull the `STR.` templates than push it forward knowing its not ergonomic in practice.

kaba0#
String Literals have been superseded by Text Blocks though, so it’s only “got pulled” as a technicality, Text Blocks are stable parts of the language now forever. I believe something similar will happen with string templates.

Also, Java has gotten an insane number of new, significant features in the last couple of years — loom, algebraic data types, pattern matching, ZGC.. I don’t want to disrespect Python, but I really don’t think they have done anything to this degree.

vips7L2 replies#
Unfortunately I think we're currently in a state where all resources are going towards project Valhalla. Everything seems to be on hold until they get that out the door.

Continue this thread — 2 replies

mands5 replies#
Technical Editor: Brian Goetz - you have my attention...
goostavos#
It has been awesome working with him.

There are few things as intimidating as having the Java language architect review your book on Java (haha). It's a much, much better book thanks to his involvement.

flakiness1 reply#
For people who're not aware: "Brian Goetz is a Java Language Architect at Oracle." (from the linked page.)
santiagobasulto#
And a great technical writer. His Java Concurrency book was a Bible back in the day (idk if still relevant).
WoodenChair#
Manning let me conduct an interview with Brian a few years ago for my book with them. Here is the transcript: https://freecontent.manning.com/interview-with-brian-goetz/

He was very generous with his time and there are some good insights there for aspiring developers, as well as some info about the evolution of Java which may be relevant to the more data-oriented features that have been added in recent times.

matsemann#
While I'm normally not a fan of appeal to authority, knowing this is what moves this from "will try to remember to check this out when I wake tomorrow" (it's 23:04 here) to "will definitely check out tomorrow".

Also it being from Manning helps. It's difficult to find good books today, so easy to self publish or get reeled in by some paper mill that banks on people wanting to have a book on their resume. So have to have something to filter out signal in the noise.

burningChrome#
Congrats on your accomplishments!

I had two friends who both wrote separate books on JS. One early book on Angular and the other was about jQuery. Both had a hard time with the critical reviews they received on Amazon and it really dissuaded them from doing any more technical writing.
I love your approach and hope you keep writing and don't let the trolls get to you! Our industry needs more people who have this "soup to nuts" approach and take into account how nearly every language has changed dramatically over time.
Again, congrats and keep writing.

Load more comments