Fwd: B3, default values, and implicit initialization

Victor Nazarov asviraspossible at gmail.com
Tue Apr 25 10:10:11 UTC 2023


On Fri, Apr 21, 2023 at 12:27 AM Brian Goetz <brian.goetz at oracle.com> wrote:

> As I mentioned yesterday, the high order bit here is how we describe a
> class whose (null-restricted) instances can tolerate (and possibly even
> encourage) uninitialized use, just as the primitives do today.
>
Ignoring the surface syntax, what we really need is an evocative term for
> such a class.
>

As a quick brainstorming options, what about the term "having immediate
default"

This term has to be useful and evocative to multiple participants:
>
>
The word "immediate" can work in multiple contexts and evoke different
associations.



>  - The client of a class, who may exploit the fact that instances may be
> safely used uninitialized, or who may want to reason about flattening.
>
 - The specification / descriptive documents, which will need a way to talk
> about "classes that are friendly to uninitialized use."
>


"Immediate" can mean that the default value is immediately available and
can be used without initialization. A declared field immediately has a
usable value. A declared array immediately has elements, without the need
to initialize them. Having values immediately allows them to be efficiently
packed (flattened).

"Immediate" can also mean ease of construction. A class with "immediate
default" can be constructed very easily using `T.default` notation or `new
T()` constructor without arguments. This expression that allows you to
construct an instance of the class is very small and obvious, so it's very
fast to write it, so you get a new instance almost immediately.


>  - The author of a class, who is making a decision about whether the zero
> state represents a sensible default.
>

For the author of the class, the word "immediate" can mean that the default
value is obvious, i. e. you can immediately see what it is, the meaning of
all zeroes is immediately clear without further explanation.


> This concept is made more difficult because this property will only have
> observable effects for variables with null-restricted types.
>
>
"Having immediate default" serves in this way to say that nothing special
is actively happening with such value classes, but if the default value is
needed for the class, then it is immediately available,

Hope this may be useful.

--
Victor Nazarov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-comments/attachments/20230425/ceae6782/attachment-0001.htm>


More information about the valhalla-spec-comments mailing list