[External] : Re: User model: terminology
Brian Goetz
brian.goetz at oracle.com
Wed May 4 17:32:39 UTC 2022
> - A term for those non-identity classes which do not _require_ a
> reference. These must have a valid zero, and give rise to two
> types, what we've been calling the "ref" and "val" projections.
>
>
> I like "zero-default" (as opposite of null-default) but mostly because
> it's a valid hyphenated keyword.
In addition to staying away from declaration syntax for purposes of this
thread, let's also stay away from defaults, so we can stay focused on
concepts.
"Default is zero" as a concept is part of the story, but I worry it may
be the dependent part. Because before you can get to "default is zero",
you need a way to say "has a sensible zero". For LocalDate, the zero is
not sensible (well, it could be, but 1970 is a pretty lousy zero value),
whereas for Complex, zero is not only valid, but is arguably a great
value. This is a semantic statement about the domain.
For a "has no sensible zero" type, the only choice is a reference, which
brings its own default -- null. So "has a sensible zero" gates "has a
val projection", but does not yet say anything about which (ref/val) is
the default.
It's nice to say "zero" directly, but I'm not sure it says what we mean
by "zero-default", since the default of the ref projection is null, like
all other refs. Obviously the example I had in my earlier mail
("zero-happy") are silly and were meant only to be evocative.
So what we're looking for is a word for "the zero value is good, so the
concept of a non-nullable instance makes sense".
Which brings me to another observation: this is a different sense of
non-nullable than what we might mean by:
void foo(String! s) { ... }
Because, a Foo.val is a type we can use as, say, an array component type
(because the zero is valid), but the traditional interpretation of
`Foo!` makes it ineligible for use as an array component (and probably a
field), because references in the heap are null-default. So when we talk
about non-nullable instances, we're really saying "there is *another*
good default other than null."
More information about the valhalla-spec-observers
mailing list