[swift-evolution] RFC: didset and willset
erica at ericasadun.com
Fri May 20 16:19:48 CDT 2016
> On May 20, 2016, at 11:41 AM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> On May 20, 2016, at 7:26 AM, Matthew Johnson <matthew at anandabits.com> wrote:
>>> (For instance, a perhaps controversial opinion: I think `dynamicType` is properly capitalized for the syntactic slot it's in. That's not to say I think we should *keep* `dynamicType`, but simply that `foo.dynamicType` is more appropriate than `foo.dynamictype` would be.)
>> +1. 'foo.dynamictype' seems strange to me.
> foo.dynamicType is broken for other reasons. I see x.dynamicType as being a named operator (like sizeof) and not a property. For example, we don’t want .dynamicType to show up in code completion on every value in the universe ("4.dynamicType”, really?).
> That argues that it should be spelled as dynamicType(x), and ideally being a standard library feature instead of a keyword.
Gist: https://gist.github.com/erica/b0155e2f6d96c3d530fdafa9b3bd6272 <https://gist.github.com/erica/b0155e2f6d96c3d530fdafa9b3bd6272>
Moving dynamicType to the standard library
Author: Erica Sadun <https://github.com/erica>
Review manager: TBD
This proposal establishes dynamicType as a named operator rather than a property and moves it to the standard library.
In Swift, dynamicType is a property. Because of that, it shows up in code completion as an "appropriate" completion for all values, regardless of whether it makes sense to do so or not. For example, Swift offers 4.dynamicType, myFunction().dynamicType, etc. Rather than express a logical attribute of a specific type, it can be applied to any expression. Since dynamicType behaves more like a operator (like sizeof), its implementation should follow suit.
Moving it to the standard library, allows Swift to remove a keyword and better aligns the functionality with its intended use.
Upon adoption of this proposal, Swift removes the dynamicType keyword and introduces a dynamicType function:
dynamicType(value) // returns the dynamicType of value
<https://gist.github.com/erica/b0155e2f6d96c3d530fdafa9b3bd6272#impact-on-existing-code>Impact on Existing Code
Adopting this proposal will break code and require migration support, moving the postfix property syntax into a prefix function call.
Not adopting this proposal
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution