Brian Goetz
cr.openjdk.java.net/~briangoetz · Personal blog · on HN since 2010
Brian Goetz, Java language architect at Oracle, publishes design documents on Java features like records, pattern matching, and Valhalla.
What HN saysHN links it for authoritative explanations of Java language design, such as why records were chosen over tuples and how specialization addresses erasure.
53HN people shared it
34linked it in comments
26stories submitted
1.1Kstory points
4 years agolast shared
2010people per year2026
Most-shared posts
- 1Data Classes for Java15 people · 268 points · first shared 2017 · 205 comments on HN
- 2Pattern Matching for Java8 people · 371 points · first shared 2017 · 146 comments on HN
- 3The Road to Valhalla7 people · 143 points · first shared 2019 · 81 comments on HN
- 4How Java got the generics it has (by Brian Goetz)4 people · 8 points · first shared 2020 · 1 comments on HN
- 5Towards Better Serialization in Java4 people · 7 points · first shared 2019 · discussion on HN
- 6Translation of Lambda Expressions in Java 84 people · 1 points · first shared 2013 · discussion on HN
- 7Language Model for Inline Classes in Java3 people · 4 points · first shared 2019 · 1 comments on HN
- 8State of the Specialization: Generics over primitives in Java and JVM2 people · 83 points · first shared 2014 · 1 comments on HN
- 9State of the Lambda2 people · 65 points · first shared 2011 · 43 comments on HN
- 10State of the (Java) Lambda2 people · 32 points · first shared 2010 · 9 comments on HN
- 11Pattern Matching for Java - Semantics2 people · 1 points · first shared 2018 · discussion on HN
- 12State of the Lambda (Single Abstract Methods in Java, etc)2 people · 1 points · first shared 2011 · discussion on HN
- 13Background: how we got the generics we have (2020)1 people · 68 points · first shared 2021 · 101 comments on HN
- 14Adding Streams to Java 8 as part of project Lambda1 people · 2 points · first shared 2012 · discussion on HN
- 15Preview of usage of closures in JDK8 collections1 people · 2 points · first shared 2012 · discussion on HN
What HN people wrote when they linked it
wilsonthewhale · 2021-01-23
If you've been following the development progress, they've gotten the VM side largely ironed out and under testing. Nothing on the language side has been polished yet though.
As an honest estimate, I'd give about 2-4 more years. But it's definitely further along than I thought it would be.
See: https://cr.openjdk.java.net/~briangoetz/valhalla/sov/
apta · 2020-06-30
This is a good read[1], and they're "fixing" them with specialization.
[1] https://cr.openjdk.java.net/~briangoetz/valhalla/erasure.html
dmitriid · 2020-02-19
Too bad pattern matching implementations in C# (possibly in JS [1] and other languages [2]) don't go beyond basically matching in switches and maybe perhaps somwewhat inside function bodies.
One of the greatest powers of pattern matching comes from being abole to match in function definitions. The simplest example:
fac(0) -> 1;
fac(N) when N > 0 -> N*fac(N-1).
This makes a lot of code much more readable and more concise.
[1] https://github.com/tc39/proposal-pattern-matching
[2] http://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html
kjeetgill · 2022-10-12
Hey, sorry if it came across as condescending, I really didn't mean it to be. All I wanted to say was I don't think the choice is obvious and leave a few googleable buzzwords for anyone interested to go read up more on it.
I don't think I took a stance pro/anti erasure other than to say I think it's way more complicated a topic than it might seem (maybe not to you, but likly to others!) and it's worth reading up on. AND I didn't want to dig up old HN comments/posts to confirm what I'd read about it, so I was necessarily vague.
Edit 1:
For instance, I vaguely recall that Scala head trouble porting to C# because of erasure related stuff. But I'm not genius enough to remember the details so I didn't get into it.
Edit 2: So I dug one up: https://cr.openjdk.java.net/~briangoetz/valhalla/erasure.html
And posted here https://news.ycombinator.com/item?id=33171832
Edit 3: Other good conversations on it: https://news.ycombinator.com/item?id=18679684
https://news.ycombinator.com/item?id=13051594
Again, my only stance is that it's a surprisingly deep topic — Not making any claims!
kasperni · 2020-02-04
That is by design (https://cr.openjdk.java.net/~briangoetz/amber/datum.html)
Why not "just" do tuples?
Some readers will surely be thinking at this point: if we "just" had tuples, we wouldn't need records. And while tuples might offer a lighter-weight means to express some aggregates, the result is often inferior aggregates.
Classes and class members have meaningful names; tuples and tuple components do not. A central aspect of Java's philosophy is that names matter; a Person with properties firstName and lastName is clearer and safer than a tuple of String and String. Classes support state validation through their constructors; tuples do not. Some data aggregates (such as numeric ranges) have invariants that, if enforced by the constructor, can thereafter be relied upon; tuples do not offer this ability. Classes can have behavior that is derived from their state; co-locating state and derived behavior makes it more discoverable and easier to access.
For all these reasons, we don't want to abandon classes for modeling data; we just want to make modeling data with classes simpler. The major pain of using named classes for aggregates is the overhead of declaring them; if we can reduce this sufficiently, the temptation to reach for more weakly typed mechanisms is greatly reduced. (A good starting point for thinking about records is that they are nominal tuples.)
pron · 2020-01-16
I meant that it's worked out pretty well for Java. ML -- one of my favorite languages, alongside Java and a couple of others -- has also managed to avoid being used by anyone, really. But look at Java now: it has generics and higher-order functions, and it's getting a uniform treatment of types (Project Valhalla), and pattern matching [1]. And so while ML introduced those features in a research context, Java is the language that has made and will make the world actually use them. Being ahead of your time is often just as much of a mistake as being behind (as far as product design goes).
As to the question of "holding programming back," it is yet to be seen how much of an impact these features have in practice. Same goes for what ML "lacked." I personally like some features more and some less, as do you, but I don't think anyone knows which programming language features really push programming forward.
[1]: https://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html
dtech · 2018-03-29
I really like (and work in) Scala, and Scala native is an interesting project.
However, its use cases seem to be encroached on all fronts.
If you want native, performance and don't need the JVM ecosystem, Rust and go both take very different but good approaches to that problem. I would have a hard time recommending Scala Native over Rust.
If you want browsers, Javascript is rapidly evolving and becoming a better lanuage. Typescript adds an excellent type system given the constraints its working with. Webassembly opens the door to use your own favorite. I would have a hard time recommending Scala.js over Typescript.
If you want JVM, Java is adopting traditional Scala killer features at a glacial pace, lambda's in 8, pattern matching in 11+ [1], Data/Case classes in ? [2], but adopting them nonetheless. Kotlin has succesfully performed a Blitzkrieg maneuver on Scala's "better Java" territory and has full support from Google in Android. It's also much more approachable for Java devs. I have a hard time convincing JVM devs that Scala is a good choise over Kotlin. At the place I work in all new projects are Kotlin, and Scala is used for the projects that were started in it.
Python and R are mainstays in the data science world, with Spark serving as a sort of Scala bastion.
I like scala, and follow its developments and 3.0 (Dotty) version somewhat, but I am slowly seeing it dwindling into irrelevance.
[1] http://openjdk.java.net/jeps/305
[2]…
signal11 · 2018-02-11
> Sun could have (and should have) copied them in Java, and I don't know why they didn't.
I had always assumed that, initially, Sun was distracted by the Oracle acquisition. But there's also a philosophical / design principle in Java which tends towards being conservative about what features they add, for instance see this discussion thread [1,2] about adding a Pair class into java.util. Given the wide deployed footprint of Java across platforms, one can even sympathize with this.
There is also the central Java philosophy (which also influences the Pairs/Tuples discussion) that "names matter"[3]. I would argue that in my experience, in some contexts, especially in the server-side enterprise context where Java is very popular, names don't always matter, which is why developers keep asking for Pairs and Tuples and keep complaining about Java's verbosity -- because Java forces them to care about things they don't really care about (another great example is checked exceptions).
C# to me is like a "mirror universe" Java, where the underlying philosophy is to add features if they make a developer's life simpler. As a result, C# "feels" nicer to use and in the right hands can result in (subjectively) nicer code. In JVM land, this also explains why so many developers like Kotlin.
In reality, developers can write unreadable code in both languages. Although my main criticism of Java is that they probably shouldn't be that dismissive of Lisp, there are some good ideas there, as…
adriaanm · 2014-07-29
I agree with most of your comment. Thanks for writing it down!
First, the agreement:
Yep, structs are a VM thing. We are very excited about Project Valhalla (http://cr.openjdk.java.net/~briangoetz/valhalla/ etc).
Refactoring in a dependently typed language is hard. There's room for improvement. Scala-refactoring is a great example of community contribution.
Scala style checking is on our roadmap for 2.12. I'm procrastinating reviewing the first PR for the tool (abide) right now.
Finally, I would like to clarify we are doing everything we can think of to encourage the community to help shape the design and implementation of Scala. We publish roadmaps, review (and even rework) community PRs, do most of our team comms publicly (we are a distributed team), solicit proposals for language changes (e.g., http://docs.scala-lang.org/sips/pending/42.type.html). We spun out library modules that are now being maintained by the community. I spent last year simplifying the core build, so that we can move to a standard sbt build this year, which should also make it easier to contribute. As a first step towards updating the [spec](http://scala-lang.org/files/archive/spec/2.11/), we converted it to [markdown](https://github.com/scala/scala/tree/2.11.x/spec).
That said, I think it's only natural that the Scala committers on Typesafe's payroll are more inclined to work on customer support issues / internal Typesafe support. We always try to strike a fair balance to give back to the…
hashmash · 2021-12-24
Brian Goetz's take on generics: http://cr.openjdk.java.net/~briangoetz/valhalla/erasure.html
papercrane · 2021-03-16
The new object type being promoted from preview feature is just the record type. Records are still Objects, they just provide a low ceremony way to create an immutable object holding some data.
I see these record classes in the same category as enum objects, an evolution of the language to improve developer ergonomics.
Upcoming is inline-classes (previous called value types.) When this happens we'll have a true "special" kind of Object, one that does not have any identity. The motivation here is mostly performance. The details are available in Brian Goetz "State of Valhalla" update https://cr.openjdk.java.net/~briangoetz/valhalla/sov/01-background.htm…
_old_dude_ · 2021-02-13
> JVM can't do dynamic dispatch on multiple arguments
It can since Java 7, the instruction invokedynamic was added for this kind of stuff.
The implementation for Pattern Matching (the project Amber) [1] will use the very same instruction.
[1] https://cr.openjdk.java.net/~briangoetz/amber/pattern-match-translatio…
samprotas · 2020-10-22
Protobuf supports "oneof" which is also cumbersome to implement in these same languages but all of them support it (with some extra LOC and no exhaustiveness checking watching your back).
Java/Go/C++ are perfectly capable of parsing a "type" key and conditionally parsing different shaped data. If you make a programming mistake here, you'll get a parse error (bad, but not a security problem). The pushback seems to be that a Java/Go/C++ implementation adds LOCS and won't gain much by doing this extra step so lets make the protocol itself match match their (less precise) data representation.
FWIW there is work towards improving Java in this regard:
https://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html
gschrader · 2020-06-29
Serialization is one of them http://cr.openjdk.java.net/~briangoetz/amber/serialization.html
pulse7 · 2020-05-01
...pass-by-value is also coming and it will be called "inline objects". See: http://cr.openjdk.java.net/~briangoetz/valhalla/sov/01-background.html
pjmlp · 2020-04-28
It will come, just not yet, because JARs compiled 25 years ago are supposed to still run unchanged in this new world.
https://cr.openjdk.java.net/~briangoetz/valhalla/sov/01-background.htm…
https://jdk.java.net/valhalla/
OWL, VCL, MFC, wxWidgets, Turbo Vision, CSet++, Motif++, BeOS, Epoch were all Java style, before Java was even born.
MrBuddyCasino · 2020-04-12
> They don't now but they likely will. See "named invocation" here: https://cr.openjdk.java.net/~briangoetz/a
This is good news!
> It has little to no influence on the Java platform it targets and its ecosystem
It certainly influenced the ecosystem by showing what is possible, and making the shortcomings of Java even more obvious. It has replaced Java (and to some degree, Scala) as the default backend language at some shops, because of less boilerplate and null-safety, leading to better and more maintainable code. Its running the apps on worlds biggest smartphone OS. It may not have pull over the JVM‘s direction, but afaik that had not been a problem so far. Kotlin‘s performance is on-par with Java.
krzyk · 2020-02-04
http://cr.openjdk.java.net/~briangoetz/amber/datum.html
There you can read about algebraic data types in java, in Java 14 you get preview for records in Java 15 probably you'll get preview for sealed types - they were developed together for some time, only recently there was a split.
pvg · 2020-02-04
There's a detailed Brian Goetz writeup about much of this at:
https://cr.openjdk.java.net/~briangoetz/amber/datum.html
mahkoh · 2020-01-16
Different components being in sync is a property of objects in general. E.g. Java's ConcurrentHashMap is mutable but its fields are in sync.
For pattern matching to see an in-sync view of the object, the object must provide such a view. If the object allows concurrent modification (most don't) then it must provide a custom view. Otherwise a generated default view should be sufficient.
If you look at [1] you can see that Goetz does propose a function that provides such a view for classes and not just records (c-f extractor.)
[1] https://cr.openjdk.java.net/~briangoetz/amber/pattern-semantics.html
AlphaSite · 2019-12-17
Its coming to java: https://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html
efge · 2019-12-06
Make sure to read the second part, Language Model (http://cr.openjdk.java.net/~briangoetz/valhalla/sov/02-object-model.ht…
MaxBarraclough · 2019-04-24
There was a project to add structs (record types without heap allocation) to OpenJDK, but it seems to be dead. [0]
There's also this less dead looking project, with goals that seem pretty similar. [1] Perhaps some day Java will finally gain this feature that obviously should have been there in the beginning. There's a reason .Net has them.
[0] http://openjdk.java.net/jeps/169
[1] https://cr.openjdk.java.net/~briangoetz/amber/datum.html
farmdawgnation · 2019-04-06
They also neglect to mention that there are active conversations in the Java community around how to effectively implement Data Classes. For example: https://cr.openjdk.java.net/~briangoetz/amber/datum.html
aardvark179 · 2019-03-20
Brian Goetz has writes quite a bit about ongoing projects. The latest article he has done about pattern matching is I think http://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html. There is a load of stuff in there about destructuring patterns from about half way down.
haglin · 2019-02-02
Data Classes for Java
https://cr.openjdk.java.net/~briangoetz/amber/datum.html
dangets · 2019-01-31
I've heard it makes Kotlin integration a pain also if you are ever planning on that. If your Kotlin code depends on Java lombok classes, the compiler fails. Most people probably don't have this concern, but IMHO a mixed Kotlin-Java project is better than any of the current 'data class' libraries available for Java (Lombok, Immutables, Joda-Beans, AutoValue) ... ymmv, and I'm eager to see what comes of the "data classes in java proposal".
https://cr.openjdk.java.net/~briangoetz/amber/datum.html
Polyisoprene · 2018-12-23
Hopefully project Amber will arrive soon.
https://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html
spullara · 2014-05-02
Well, for one, Lambdas are desugared into methods, not anonymous classes. Early on they used anonymous classes because it was convenient but that wasn't the final translation strategy.
http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html