valhalla-dev Digest, Vol 6, Issue 3
Brian Goetz
brian.goetz at oracle.com
Sun Dec 21 16:47:25 UTC 2014
> 1) List<int>.remove() disambiguation
Your solution here amounts to a deprecation mechanism with hints, which
is an OK solution to the remove(int)/remove(Object) problem. (I'm a
little mystified, though, how everyone seem to assume that the remove
overload conflict is the only problem that Peeling addresses itself to,
and if somehow that one could be solved, the whole rest of the exercise
is pointless.)
What's your story for the Collection method
removeAll(Collection<?>)
in such a way that a removeAll method could be called from generic code
like:
<any U> removeAllFrom(Collection<U> originalCollection,
Collection<? extends U> eltsToRemove) { ... }
> 3) "Empty" values
> --------------------------
> - as somebody pointed out, we need a syntax that references 'empty' values
> by type; null or zero.
> - I propose 'T.empty' for this purpose; eg, int.empty references 0,
> Object.empty references null.
Minus ten points for digressing into syntax. There are infinitely many
possibly syntaxes for this, and they *all* will be suggested eventually,
but unfortunately such discussions have a tendency to choke off actual
useful discourse. Right now, we're figuring out the right model, and
there's more than enough work to do there.
> 4) Map<int>.get() and "sentinel values"
> --------------------------------------------------------
> - null is a moderately good "sentinel value" for objects, but zero is not
> so good for numbers;
> - similar to the 'T.empty' syntax proposed above, I propose a 'T.sentinel'
> syntax for "no element".
> eg, int.sentinel references -1, Object.sentinel references null.
The reason int can't be null is that we have no natural and efficient
hardware representation for it; all 2^32 values in an 32-bit integer are
used for integers. So changing the syntax from "null" to "sentinel"
doesn't help -- the real problem is, how do we represent it? Ballooning
all integers to 64 bits just to accommodate a special value is not going
to fly. And stealing "-1" as the "not to be used as an int" value
similarly doesn't fly; -1 is also an important integer.
Applications and APIs are free to cut corners like "let's let -1 mean
'no value'", but languages and VMs are not free to do this.
And, minus ten points more for another syntax digression :)
> 5) Statics; synchronizing to access these?
> ----------------------------------------------------------------
> - good point about SomeType<int> and SomeType<T extends Object> sharing the
> same statics;
> - but since they do not have class in common, what syntax/ or common object
> can they synchronize on?
> - possible proposal: T.classLock, which should be the base Class (but
> perhaps just typed as Object).
Agree that being able to denote "the class that hosts my static members"
is desirable. Syntax can wait.
> - I called my null-handling class "Optional" back at Java 5. Now some
> dropkick comes along and pollutes my namespace with these
> poorly-thought-out & incomplete FP ideas.
Thanks, I was that dropkick.
> 7) Peeling and Layers
> --------------------------------
> - these ideas seem major & complex, but solve only relatively moderate
> corner cases.
I think you're giving them too much weight, perhaps because they're new
and scary. These are not intended to be, to use your term, a "banner"
feature; our hope would be that they almost never get used. And yes,
they currently have a lot of surface. See separate note on the subject.
> - introducing a major new structural level into the Java language, breaking
> long-standing single Java types into separate parts is an enormous change;
> seemingly suitable for "mixins" or some really major language enhancement.
> - yet the parts/layers are not named/ or addressible, and the use of this
> structure will really be quite minor.
>
> Summary: introducing a banner-level language feature to solve two
> problematic methods, with no other possible use, does not really seem the
> right design choice.
>
>
> 8) Conclusions
> ----------------------
>
> Introduction of a simple "field-style" syntax on types extends the existing
> usage of ".class", to allow important new type-related expressions to be
> expressed in an easy & obvious way. It also gives minimal potential for
> conflict with existing syntax.
>
> I am much happier to avoid cast-based formulations, such as casting 'null'
> to int, to get zeros/nulls in a type-specific way. Introducing a
> well-defined syntax for "empty" and "sentinel" values could resolve most
> no-item & empty-value problems -- which is where null & null problems
> typically crop up -- in an effective manner.
>
> I absolutely think we need a type-specific method/ or syntax for null-safe
> equals; this is a basic to writing most collections code. However, I'm
> less clear on what "the right" syntax should be here. Any takers?
>
> Look forward to your thoughts,
>
> Regards
> Thomas Whitmore
>
More information about the valhalla-dev
mailing list