[records] updates for Preview 9. hashCode
John Rose
john.r.rose at oracle.com
Tue Jan 14 23:35:22 UTC 2020
On Jan 14, 2020, at 3:05 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>
>
>>
>> This is almost OT but it's a question I was asked for twice,
>> what is the rational to use the angle bracket instead of the parenthesis ?
>
> I surveyed a variety of implementations of toString(), and picked what seemed most common, which was some variant of:
>
> Type[v=vVal, u=uVal]
>
> Which was good enough. Yes, we could bikeshed it, but I'm not particularly seeing a problem that needs to be fixed, and it doens't seem obvious to me that highlighting the record-ness of it is important at toString-time? It's the state that matters.
In practice record-ness will be clear at a glance from the class name.
I see no downsides to the existing syntax and am (like Brian) uninterested
in exploring alternatives to this particular punctuation polarity.
— John
P.S. …OK, in the interests of defending this position FTR, here’s
some additional rationale. This is not intended as an invitation to
explore other designs which might have better rationales!
A record is, first of all, a tuple, with an immediate proviso that it’s
nominal, having a named type and named components. As a tuple
it’s sequential and heterogeneous. As a nominal entity its components
are keyed, allowing strongly type access. It is not indexed like a
homogeneous entity.
Lists, arrays, and sets print with square brackets, and records like them
are sequential data structures (though heterogeneous), so they too print
with square brackets.
Unlike lists and arrays, the nominal information is added as decorations.
The decorations follow the precedent of (Abstract)Map, but the
similarity to Map is not close enough to mandate closer similarly
to Map syntax. In particular, Maps are not (usually) ordered,
and cannot be interpreted (usually) without reference to keys.
Records unlike maps are always ordered and can be interpreted
as pure tuples (as well as maps).
Record: heterogeneous, sequential, keyed, N[a=x,b=y].
tuple*: heterogeneous, sequential, indexed, (x,y).
List, array: homogeneous, sequential, indexed, [x,y].
Set: homogeneous, non-sequential, self-keyed, [x,y].
Map: homogeneous, non-sequential, keyed, {a=x,b=y}.
See also:
MethodHandle: MethodHandle(A)T
MethodType: (A)T
(*) hypothetical in Java, math notation cited.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200114/fe2afc99/attachment.htm>
More information about the amber-spec-experts
mailing list