"Actors are reference types, but why classes?"

You're misinterpreting my point: the proposal simplifies the rule by separating actor class and non-actor class hierarchies. You're interpreting that as evidence that "these two things must be completely different," when it is not: it's a simplification of the more precise rule I stated.

Subclassing introduces complexity, but beyond the inheritance of initializers, you really can't blame Objective-C for any of it. The argument that "we don't have Objective-C so we don't need subclassing" doesn't follow.

The reasons for subclassing are identical for actors and classes. It provides implementation inheritance and shared storage for subclasses (something people ask for protocols to do). Subclassing provides more efficient dynamic subtyping checks (as? to a subclass will always be much faster than as? to a protocol) and cheaper existentials (one pointer vs. 1+number of protocols pointers).

And existing class hierarchies that make use of these features can migrate over to actor classes if actor classes support subclassing. Take away subclassing and you're forcing folks to rewrite more code to adopt concurrency. Have we improved their experience, or have we thrust our own opinions on them?

They get all of the problems of shared mutable state. They don't run into any of the other issues with subclassing because there aren't meaningful dynamic subtyping relationships, nor do they conform to protocols.

Those are value types with a different storage mechanism, not reference types.

I really, really do understand why folks don't like subclassing. I wouldn't choose to have it in a language, but it's there now, and it will not be going away. It solves real problems for Swift developers, and they use it. And if you don't like it, it doesn't hurt you: final takes it away and you've lost nothing, and for the most part you don't even need to write final for subclassing to be irrelevant if you don't use it.

Doug

3 Likes