[swift-evolution] [Pitch] Rename `AnyObject` to `AnyClass` and drop current `AnyClass`

Adrian Zubarev adrian.zubarev at devandartist.com
Thu Jun 9 06:55:14 CDT 2016


On 9 Jun 2016, at 9:23 PM, Adrian Zubarev via swift-evolution <swift-evolution at swift.org> wrote:

So what is the counterpart to AnyClass aka. AnyObject.Type for AnyValue? There is no and I don’t see any good name for it.

You could just use AnyValue.Type?
So basically you’re for consistency for `AnyValue` but not for current `AnyObject`.

It’s clear that `AnyValue` can represent more than one value type, where `AnyObject` can only represent one reference type (class). IMO for consistency it should be named as `AnyClass`.

More confusion with generalized existentials:

Any<class> vs. AnyClass aka AnyObject.Type
Any<class> makes it crystal clear that you’re using an instance of a class not an instance of .Type. It should be consistent.

Any<…> would be used for any of a certain type. So Any<class> to me says ‘any of class’, not ‘any class’. Whereas AnyClass says to me literally ‘any class’.
`Any<class>` and `AnyClass` should be the same otherwise it will lead to confusion!

If someone is new to the language and reads `AnyObject.Type` its not clear that a `.Type` instance of a class is meant, because its not clear what `Object` might be. 

If then you also have existentials with any-class requirements and `AnyClass` typealias which is `AnyObject.Type` it would definitely lead to confusion between:

func foo(value: AnyClass & SomeProtocol) // this would be illegal with current implementation

vs.

func foo(value: Any<class> & SomeProtocol)

If one would want to use a `.Type` instance then should always type out `.Type` suffix after your type name: `AnyClass.Type` == any `.Type` instance of any class

I'm strongly against keeping `AnyClass` as an alias for `AnyObject.Type`, I’d consider to keep only `AnyObject` but if `Any<>` existentials were to come we’d get this mismatch:

typealias AnyObject = Any<class>

-- 
Adrian Zubarev
Sent with Airmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160609/3600d2cc/attachment.html>


More information about the swift-evolution mailing list