<div dir="ltr">I'm very interested in reflection in Swift. As Joe says, designing interfaces takes time, but since one of the goals of Swift 3 is to stabilize the ABI, and since the ABI might affect the ability to perform reflection operations, or at least their performance, it's important to work this out sooner rather than later. If there's any help I can provide in that regard, I'm happy to provide it.<div><br></div><div>I do have a question about precisely what you mean by "readwrite reflection". I assume you mean adding/removing/swizzling properties/functions at runtime, but it's possible you mean get property values by name, but don't set property values by name. I definitely want to set property values by name. I would like to be able to, for example, write an implementation of decodeObjectOfClass:forKey which walks a class or struct's public properties and sets them automatically.</div><div><br></div><div>I don't have any need for .NET-style reflection security, but it doesn't negatively impact me either.</div><div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 17, 2015 at 11:21 PM, Gergely Orosz via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">(forwarding a discussion on Swift reflection from swift-users)<br><br>It seems there is no disagreement on how reflection is something we would want in Swift. Given that until this is part of the language, it will be a blocker for several types of projects - both mocking frameworks, and data modeling runtime (as Jens Alfke mentioned) - I would be keen to understand the constraints swift wants to have in place so we can put a proposal together.<div><br></div><div>Specifically:</div><div>- Regarding interfaces, is there any direction or proposal on the interfaces to be used for reflection, or is this up for discussion?<br>- Regarding security, what model would the goal be? Would something like the .NET security model (classes declaring security critical attribute cannot be accessed using readwrire reflection be suffcient? Details on this: <a href="http://bit.ly/1RVQc5J" target="_blank">http://bit.ly/1RVQc5J</a> ). To my knowledge .NET has the most tight reflection rules in place, all other popular typed languages (e.g. Java, Ruby) are all more relaxed.<br></div><div>- Would secrecy also be a language goal on top of security - e.g. the ability to disallow even read reflection for certain members?</div><div><br></div><div>- Gergely</div><div><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Joe Groff</b> <span dir="ltr"><<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>></span><br>Date: 17 December 2015 at 22:07<br>Subject: Re: [swift-users] Reason for Swift not having readwrite reflection<br>To: Gergely Orosz <<a href="mailto:gergely.orosz@gmail.com" target="_blank">gergely.orosz@gmail.com</a>><br>Cc: <a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><br><br><div style="word-wrap:break-word"><span><br><div><blockquote type="cite"><div>On Dec 17, 2015, at 10:54 AM, Gergely Orosz via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div><br><div><div dir="ltr">As a user of swift, building projects on top of it, the single biggest limitation I've come across is that <b>all </b>my unit tests are significantly more bloated compared to Objective C... because mocking & stubbing is not possible due to the static nature of the language and that readwrite reflection is not supported.<div><br></div><div>I did some research and apart from C++ and C I couldn't find any other popular language that does not support readwrite reflection (here's a post I wrote on the topic: <a href="http://bit.ly/1PbgSys" target="_blank">http://bit.ly/1PbgSys</a> ).</div><div><br></div><div>Not having readwrite reflection makes it impossible to create any mocking frameworks for unit testing, which is a very common tool in the testing world. Without this we're left with using dummies and fakes - for now creating them manually, in the future I'm sure there will be plugins that support generating these from e.g. protocols.<br></div><div><br></div><div>The iOS community seems to be somewhat behind when it comes to automation compared to other languages and platforms - and in its current version Swift seems to make the barrier to entry even higher compared to Objective C, where mocking and stubbing is a possibility due to the dynamic nature of the language.</div><div><br></div><div>Could anyone shed some light on why the decision was made to leave this feature out? Is it just a feature that due to complexity will be pushed for later? Or is it a security consideration?<br></div></div></div></blockquote><br></div></span><div>Yes, yes, and yes. Better reflection is something we'd like to support eventually, and a lot of the necessary metadata is already present at runtime, but not exposed. Designing interfaces takes time, and there are also security and secrecy concerns regarding what ought to be reflected, so there needs to be language design as well to control what is available to runtime reflection. All that said, runtime reflection is not the only way to approach mocking and stubbing. Swift's as static as you write it; if you define your component interfaces using protocols and generics, those protocols can be conformed to with mock or stub implementations without any need for runtime hacking.</div><span><font color="#888888"><div><br></div><div>-Joe</div></font></span></div></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=HDu-2BON2WuckNVJ2U1s3AlFgVD2xwU1HZRuo94MM4tGuKTTLb2VpcYo7Ky-2FMOv-2B8M-2BFaX9mOPYe7SlvzMG9hQrHxR6FlOj-2FyUexCa8Qe57xBBmxj1MDUX1WxV2HPaOJ7o6eePralp-2B-2F2L0ZfZKSbzZxaQMHCKhjBWldhppEezUYAI1fBKZmwwy5zku5bx9uXCSM-2FcJMOaGwniIWsKr6syJqE9KnSiyqg2SaDDx-2BnuXns-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>