[swift-evolution] [Proposal] Explicit Synthetic Behaviour

Haravikk swift-evolution at haravikk.me
Wed Sep 6 16:06:08 CDT 2017


> On 6 Sep 2017, at 16:26, Eagle Offshore <eagleoffshore at mac.com> wrote:
>> On Sep 6, 2017, at 1:32 AM, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
>> As a general rule I would argue that Mirrors should almost never be used for any purpose, except perhaps debugging; in production code they can lead to subtle and misleading problems, not to mention any performance impacts. Even for things like serialising types, it is not a desirable way to do it, and should only be used as a last resort because of missing features in Swift.
> 
> I'm just going to toss in that you and I apparently have diametrically opposed needs and belief systems about what makes for a good programming language.  I believe the exact opposite.
> 
> After 20+ years of Cocoa development, I rely on these features heavily and consider any language that lacks them to be more or less "dead" where I consider languages that have them to be "self aware" and "lively".
> 
> For instance, I think relying on the compiler to generate special code to implement Codable rather than just exposing the meta facilities required to do introspection is taking the long way around rather than the short cut.
> 
> So add my vote for powerful reflection capabilities.  

Sorry I think my remark was unclear; my comment there was specifically about the use of run-time reflection, which I believe usually indicates a failure of a language to provide other, more appropriate features (like Codable in fact). I'm not against the features where they make sense and are implemented in well, I was just pointing out that the use of run-time reflection in code is usually a sign of a last resort.

That's not really important though; the issue I'm trying to raise is that when those, and similar features, are used in synthesised behaviour (default implementations based upon the concrete type), that these behaviours should be opted into explicitly, otherwise they open up potential for all kinds of bugs, even when the assumptions being made about the concrete type are simple such as in the case for Equatable/Hashable. There's just too much potential for this kind of reflective protocol implementation to overreach; to me it feels very much like going into a restaurant and the waiter coming across and force-feeding me something I don't want instead of taking my order.


More information about the swift-evolution mailing list