[swift-evolution] Revise GCD API to conform to API Design Guidelines

Colin Cornaby colin.cornaby at mac.com
Mon Feb 15 14:24:37 CST 2016


Is there guidance from the Swift team in making C code conform with the Swift design guidelines? I know that there is an effort to apply it to imported Obj-C API, but I wasn’t aware of any guidance on C API. There are a lot of C libraries floating around out there that Swift so far is not trying to change, and so far I’m ok with that.

I’d favor leaving it alone. It’s an existing cross platform open source library. I’d like it to continue to be consistent with where it’s used elsewhere. I’m not huge on the idea of making everything a class level function, and it looks like this proposal is trying to make a set of C functions look like a Swift class.

As others have mentioned, this seems like something someone could wrap, but I don’t feel GCD as it stands is that scary. :)

> On Feb 13, 2016, at 7:48 AM, Scott Gardner via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hello everyone!
> 
> I would like to submit the following rough sketch of a proposal to revise the GCD API syntax to adhere to the API Design Guidelines, in order to gauge interest and collect feedback and suggestions.
> 
> Here is a preliminary proposal outline:
> 
> Author: Scott Gardner
> 
> Introduction
> 
> I propose that the Grand Central Dispatch (GCD) API be revised. GCD function signatures use snake-casing and are devoid of parameter names. This syntax does not conform to the Swift API Design Guidelines (“API guidelines”).
> 
> 
> Motivation
> 
> The GCD API provides a rich set of capabilities for writing concurrent code. Yet GCD’s syntax can be a barrier to entry for developers, because it does not conform to the API guidelines.
> 
> 
> Proposed solution
> 
> I propose revising the GCD API to follow the API guidelines. For example, instead of writing the following code to execute an operation asynchronously and then return to the main queue, such as to update the UI...
> 
> let concurrentQueue = dispatch_queue_create("com.scotteg.concurrent", DISPATCH_QUEUE_CONCURRENT)
> 
> dispatch_async(concurrentQueue) {
>   // ...
>   
>   dispatch_async(dispatch_get_main_queue()) {
>     // ...
>   }
> }
> 
> …this should be able to written in a more Swifty manner, e.g.,...
> 
> let concurrentQueue = GCDQueue(.Concurrent, withIdentifier: "com.scotteg.concurrent")
> 
> GCD.enqueueOn(concurrentQueue) {
>   // ...
>   
>   GCD.enqueueOn(.Main) {
>     // ...
>   }
> }
> 
> 
> Detailed design
> 
> TBD
> 
> 
> Impact on existing code
> 
> This would be a wholesale replacement of syntax for the GCD API. A utility should also be created to convert pre-existing GCD code to the new syntax.
> 
> 
> Alternatives considered
> 
> TBD
> 
> 
> I would really appreciate your comments and suggestions, and I'd certainly be willing and committed to completing this proposal based on community feedback.
> 
> Thanks!
> Scott
> 
> --
> Scott Gardner
> http://scotteg.com <http://scotteg.com/>
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160215/a211a21b/attachment.html>


More information about the swift-evolution mailing list