Java: Rethink Domain Primitives with Valhalla
dfa1.github.io
Java: Rethink Domain Primitives with Valhalla
1–10 of 13 posts
Re: Java: Rethink Domain Primitives with Valhalla
#2I’d love feedback from folks who’ve experimented with Valhalla or have opinions on modelling domain types in Java.
Re: Java: Rethink Domain Primitives with Valhalla
#3Valhalla removes the historical performance tax on tiny domain objects. This article argues that value classes finally make domain‑safe primitives practical in real systems — strong invariants, flat layout, no wrapper overhead. I’d love feedback from folks who’ve experimented with Valhalla or have opinions on modelling domain types in Java.
I can only really say one thing here: they are really late to the party with this but it's good. The performance boost will be welcome, and would probably change ORMs forever if applied right.
Nullability rules should of course be also part of this domain-constricted types concept, since it would solve a lot of accidental mistakes. Because that's what a type system is for, right? Validation of programmer input.
Re: Java: Rethink Domain Primitives with Valhalla
#4Re: Java: Rethink Domain Primitives with Valhalla
#5Valhalla removes the historical performance tax on tiny domain objects. This article argues that value classes finally make domain‑safe primitives practical in real systems — strong invariants, flat layout, no wrapper overhead. I’d love feedback from folks who’ve experimented with Valhalla or have opinions on modelling domain types in Java.
Won't this be an issue for JPA/JSONB? `null` is a an important and value in JSON and nearly every database, and for modeling the real world.
Re: Java: Rethink Domain Primitives with Valhalla
#6Valhalla removes the historical performance tax on tiny domain objects. This article argues that value classes finally make domain‑safe primitives practical in real systems — strong invariants, flat layout, no wrapper overhead. I’d love feedback from folks who’ve experimented with Valhalla or have opinions on modelling domain types in Java.
> Value classes cannot be null. Won't this be an issue for JPA/JSONB? `null` is a an important and value in JSON and nearly every database, and for modeling the real world.
Null is the thing which it isn't. A null value is evidence that your modelling does not fit the domain.
Re: Java: Rethink Domain Primitives with Valhalla
#7Earlier quoted context omitted.
> Value classes cannot be null. Won't this be an issue for JPA/JSONB? `null` is a an important and value in JSON and nearly every database, and for modeling the real world.
It is not. Null is the thing which it isn't. A null value is evidence that your modelling does not fit the domain.
I guess since basic types, like an int or double, cannot be null, I understand why these cannot be null. This unfortunately limits their usefulness, but it's a carryover from the underlying properties of the basic type.
Re: Java: Rethink Domain Primitives with Valhalla
#8Earlier quoted context omitted.
It is not. Null is the thing which it isn't. A null value is evidence that your modelling does not fit the domain.
Unfortunately, the simple fact is that one can be handed a JSON document with non-existent keys, and one can be handed a database row with a null column. Often, the programmer may handed a schema from a third party they have no control over: opening a semantics debate is likely not a good course of action. I guess since basic types, like an int or double, cannot be null, I understand why these cannot be null. This un…
Re: Java: Rethink Domain Primitives with Valhalla
#9Earlier quoted context omitted.
It is not. Null is the thing which it isn't. A null value is evidence that your modelling does not fit the domain.
Unfortunately, the simple fact is that one can be handed a JSON document with non-existent keys, and one can be handed a database row with a null column. Often, the programmer may handed a schema from a third party they have no control over: opening a semantics debate is likely not a good course of action. I guess since basic types, like an int or double, cannot be null, I understand why these cannot be null. This un…
Re: Java: Rethink Domain Primitives with Valhalla
#10Oh cool. It's newtype from Haskell 1.3 (1996). https://www.haskell.org/definition/from12to13.html#newtype