Substitutability, was Re: Finding the spirit of L-World

Brian Goetz brian.goetz at oracle.com
Sat Feb 23 13:43:19 UTC 2019



> I've said it before, but references are a kind of value too

Dude, you're preaching to the choir ;)

But, for whatever reason, people have a hard time with this notion. 
Every time I've said "references are values too", people look at me like 
I have two heads.  (Think of the old trick exam question, "Does Java 
pass objects by reference or by value", and the accepted answer is 
"neither, it passes object references by value."  The SO page for this 
question has like a zillion upvotes.)  So while clearly true, its a 
harder sell.

To be clear: before Valhalla, the JVM had two kinds of values, refs and 
primitives, and == was a reasonable approximation for the value-equality 
operator (modulo NaN, grr.)  After Valhalla, it will have three -- refs, 
primitives, and values.  And yes, what I'm selling is that == is still 
the value-equality operator.

But its possible that, with a sufficient PR campaign, people could get 
this.  (So the question becomes: is turning people's intuition here 
worth the effort, or should we play to existing intuitions?) One piece 
of this might be finding a different name for "value type", so that 
"there are three kinds of values: refs, primitives, and values" didn't 
sound so silly.  (C# calls them structs, which is possibly the worst 
name you could come up with, so not that.)

> More radically, I think a lot of the debate here is due to the syntax
> pain, which would go away if an additional operator was added to Java:

I think its optimistic to think the pain "goes away" with more syntax.  
It would just move, to angst over understanding the differences between 
the now-THREE kinds of equality operators; that doesn't feel like 
winning to me.  I would rather work within the syntax we have, and try 
to guide people to a more relevant intuition (such as, one that doesn't 
have its roots in an interpreted cost model.)







More information about the valhalla-dev mailing list