On Thu, Jul 26, 2012 at 7:28 PM, Paul Phillips <
pa...@improving.org> wrote:
>
>
> On Thu, Jul 26, 2012 at 10:10 AM, Paolo G. Giarrusso <
p.gia...@gmail.com>
> wrote:
>>
>> In particular, I'm wondering whether this would fit in Predef (code from
>> that answer with some renaming):
>
>
> We should completely reconsider the naming of:
>
> classOf
> isInstanceOf
> asInstanceOf
>
> ...in light of the existence of ClassTags and TypeTags, which mean that each
> of those now has at least one variation with different semantics, and we
> have similar methods like "typeOf" which looks like an obvious peer to
> "classOf" but is completely different.
I agree with your point, especially in an ideal world. But if you
propose renaming them before the proposed non-compatible Scala 3.0
(from Martin's "Scala - a Roadmap"), I think that it's too late—that
risks breaking too much code. A deprecation cycle could help,
refactoring tools would help more, but this sounds too late.
> I do not believe any set of names can be grafted on which will adequately
> convey the relationships between these methods.
But that begs the question: if no adequate names really exist, is it
worth changing them? The obvious answer sounds like "but there might
be something better". I'm going to shoot for that.
With all this disclaimers, if you drop the implicit brevity
constraint, I'd start by calling
class-based isInstanceOf -> isDynamicallyErasedInstanceOf, maybe
together with the current name as an alias.
TypeTag-based isInstanceOf -> isStaticallyNonErasedInstanceOf.
Am I missing more differences between the two to reflect in the names?
I'm confused by the "-ally" suffix there, since I have the impression
adjective-adverb distinctions are usually dropped in names
(counterexamples are appreciated), but "is statically an instance"
makes much, much more sense than "is a static instance".
These names should also convey the fact that none of them is better
than the other (which I missed for a while while writing the new
isInstanceOf). In particular, assuming an orthogonal design space,
nonErasedInstanceOf implies erasedInstanceOf, but
dynamicallyInstanceOf implies staticallyInstanceOf. In fact, the
design space is not so orthogonal since types are erased,
so the theoretically perfect isDynamicallyNonErasedInstanceOf can't be
implemented.
but there's space for isStaticallyErasedInstanceOf, which is
(somewhat) useful to understand why the other two disagree when they
do, I think.
We have the implication chain isStaticallyNonErasedInstanceOf =>
isStaticallyErasedInstanceOf => isDynamicallyErasedInstanceOf; it
follows that isStaticallyErasedInstanceOf is the closest approximation
of isDynamicallyErasedInstanceOf. Although you need this when you're
playing evil tricks, these tricks are often needed (and used even in
the standard library - to wit, see uncheckedVariance).
However, I don't see an easy way to erase a TypeTag to the
corresponding existential to implement isStaticallyErasedInstanceOf.
I'm sure it's possible since the compiler does it, but I'd like a
method in TypeTag for it.
This also begs the question: why does a TypeTag _not_ contain a
ClassTag or at least a Class? Writing [T: ClassTag: TypeTag] is not
fun. Worst-case, any proper type can be erased to Any, and you don't
have (directly) values of type TypeTag[T] if T is a type constructor.
Best regards
--
Paolo Giarrusso - Ph.D. Student, Philipps-University Marburg
http://www.informatik.uni-marburg.de/~pgiarrusso/