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

Patrick Smith pgwsmith at gmail.com
Thu Jun 9 07:00:25 CDT 2016


> On 9 Jun 2016, at 9:55 PM, Adrian Zubarev via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> On 9 Jun 2016, at 9:23 PM <http://airmail.calendar/2016-06-09%2021:23:00%20MESZ>, Adrian Zubarev via swift-evolution <swift-evolution at swift.org <mailto: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`.
> 
There could be one day more than one reference type, and AnyObject could also work with that.

>> 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 Any<class> was introduced, then I’d advocate for it being an outright replacement and just removing AnyObject.
> 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
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160609/18814c7f/attachment.html>


More information about the swift-evolution mailing list