IdentityObject/InlineObject naming
Stephen Colebourne
scolebourne at joda.org
Tue May 19 23:44:52 UTC 2020
Some comments wrt IdentityObject/InlineObject naming.
The current valhalla state is that "Inline classes have some
restrictions compared to ordinary (identity) classes; they are final,
their fields are final, and their ability to participate in
inheritance is limited." But these restrictions imply to me that there
are three concepts a developer might want to express in the future:
- an "identity" object (needs identity/synchronization for compatibility)
- a "plain" object (no need for identity/synchronization)
- an "inline" object (needs to be inline for performance and can
accept the restrictions)
While it is understandable that there is a reluctance to open the can
of worms for "plain" objects, they are clearly a basic concept. ie.
once you discuss the presence of identity, you naturally discuss the
absence of it. Yet the concepts around inline are in many ways
orthogonal. (Imagining a world where "plain" objects were added to
Java, then 10 years afterwards "plain" objects would be the norm, and
"identity" objects would be very rare). I mention the above, because
it bears on the naming choices available. Even if you don't want to
tackle plain objects now, the naming choice could make it harder to
add them later.
I also struggle with a single interface extends/implements hierarchy
because developers can write "extends Object" today:
- "class Foo" (default) => identity
- "class Foo extends Object" => identity
- "class Foo extends Object implements ObjectIdentity" => identity
- "class Foo extends Object implements ObjectInline" => identity and inline ???
With a single new interface, the hierarchy is implying that
"implements ObjectInline" *subtracts* identity, something that object
hierarchies do not do.
Keeping an ObjectInline interface appears better placed to tackle this
particular pedagogical problem, as it seems more explainable that:
- a class always extends Object
- a class always implements either ObjectIdentity or ObjectInline
- the defaults are "extends Object" and "implements ObjectIdentity"
ie. this makes more sense because manually writing "extends Object"
only impacts bullet point 1, not bullet points 2 and 3
Some other possible names:
- ObjectIdentifiable / ObjectInlineable
- JvmIdentifiable / JvmInlineable
Stephen
More information about the valhalla-spec-comments
mailing list