[swift-evolution] [Review] SE-0070: Make Optional Requirements Objective-C only

James Froggatt conductator at ntlworld.com
Tue Apr 26 05:33:56 CDT 2016


Fair enough. Upon reflection, I think my real issue is somewhat different to what I suggested previously.

I wasn't intending to suggest such a thing would be practical, just that it would be a decent alternative to optional protocol requirements. The alternative given in the proposal seems to be more of a way to remove optional protocol requirements on the surface, while actually helping to make them a native feature, if you see what I mean. It's not a realistic alternative - it's a worse syntax for the exact same thing, which also comes with awful side-effects for Swift as a whole. No-one would ever seriously consider this as an alternative, yet it's listed as under the heading ‘Alternatives Considered’.

You say the arguments given against optional closure properties are strong, but I don't they would be nearly as relevant to the case I suggested. By making them properties of the table view, the tableView parameter would be eliminated, meaning the property names could be unique.

EG:
var numberOfRows: (inSection: Int) -> Int
var cellForRow:: (at: NSIndexPath) -> UITableViewCell
var moveRow: (from: NSIndexPath, to: NSIndexPath)

This removes the need to add the mentioned workarounds, since a function could be assigned to the closure property just as easily as an inline closure. I feel this is much more worthy of being considered as an alternative. The idea of these proposals is to document why we do things, so at least for someone wondering why we require all this @objc syntax rather than support optional protocol requirements natively, this would actually present them with a viable alternative which could be applied in their APIs.

Thanks for the consideration of my previous email. Sorry for being a bit pedantic, but I do feel there's something off about the proposal as it is written, for it to completely fail to provide any realistic alternative to optional protocol requirements that can be applied by future Swift developers.

From James F

> On 26 Apr 2016, at 04:06, Douglas Gregor <dgregor at apple.com> wrote:
> 
> 
>> On Apr 25, 2016, at 12:18 PM, James Froggatt via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Eliminating optional protocol requirements is fine by me. The proposal mentions ‘correcting’ the optional protocol requirement pattern by changing the methods to optional closure properties, but my feeling is that this ‘solution’ just acts to continue and perhaps encourage the anti-pattern established by ObjC. I think a native Swift design would be much better off using optional closure properties on the table view itself.
>> 
>> A common theme in these ObjC optional protocol requirements is the first parameter being an instance whichever class ‘requires’ the method. Yet on the rare occasion of the instance potentially having more than one value, the implementation for each instance is often so different that my first action will be to add a switch between the possible instances (which, of course, means having those components available as IBOutlet properties anyway).
>> 
>> I suggest a much better solution to optional protocol requirements in Swift is the creation of wrappers for UIKit components. These would implement the protocol requirements, and expose optional closure properties for their their public API. Making them properties makes it far clearer that the behaviour of the container will change if a value is provided, and would remove the persistent need to apply @objc to any Swift types dealing with UIKit. I understand this would be a manual task, but I just don't think there is a good automatic solution to this problem.
> 
> There are ~800 optional requirements in the iOS SDK and ~1000 in the OS X SDK. That too large a manual task to accomplish.
> 
> Also, I think the arguments in the proposal against the optional-closure-properties approach are fairly strong: it doesn’t seem like a good way to model Objective-C optional requirements.
> 
>    - Doug
> 
> 
>> 
>> ------------ Begin Message ------------ 
>> Group: gmane.comp.lang.swift.evolution 
>> MsgID: <A57B248C-9679-450A-A09D-8C0A5E3846E8 at apple.com> 
>> 
>> Hello Swift community,
>> 
>> The review of "SE-0070: Make Optional Requirements Objective-C only" begins now and runs through May 2. The proposal is available here:
>> 
>> https://github.com/apple/swift-evolution/blob/master/proposals/0070-optional-requirements.md
>> 
>> Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at
>> 
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> or, if you would like to keep your feedback private, directly to the review manager.
>> 
>> What goes into a review?
>> 
>> The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
>> 
>> * What is your evaluation of the proposal?
>> * Is the problem being addressed significant enough to warrant a change to Swift?
>> * Does this proposal fit well with the feel and direction of Swift?
>> * If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
>> * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
>> 
>> More information about the Swift evolution process is available at
>> 
>> https://github.com/apple/swift-evolution/blob/master/process.md
>> 
>> Thank you,
>> 
>> -Chris Lattner
>> Review Manager
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> � �
>> 
>> ------------- End Message ------------- 
>> 
>> 
>> 
>> From James F
>> 
>> 
>> From James F
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 



More information about the swift-evolution mailing list