<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">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.<div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">As others have mentioned, this seems like something someone could wrap, but I don’t feel GCD as it stands is that scary. :)</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 13, 2016, at 7:48 AM, Scott Gardner via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hello everyone!</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">Here is a preliminary proposal outline:</div><div class=""><div class=""><br class=""></div><div class="">Author: Scott Gardner</div><div class=""><div class=""><br class=""></div><div class=""><b class="">Introduction</b></div><div class=""><br class=""></div><div class="">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”).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><b class="">Motivation</b></div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><b class="">Proposed solution</b></div><div class=""><br class=""></div><div class="">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...</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> concurrentQueue = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">dispatch_queue_create</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"com.scotteg.concurrent"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, </span><span style="font-variant-ligatures: no-common-ligatures" class="">DISPATCH_QUEUE_CONCURRENT</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">dispatch_async</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">concurrentQueue</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// ...</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(61, 29, 129);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">dispatch_async</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">dispatch_get_main_queue</span><span style="font-variant-ligatures: no-common-ligatures;" class="">()) {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// ...</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; }</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">…this should be able to written in a more Swifty manner, e.g.,...</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> concurrentQueue = GCDQueue(.Concurrent, withIdentifier: </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"com.scotteg.concurrent"</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">GCD.enqueueOn(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">concurrentQueue</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// ...</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; GCD.enqueueOn(.Main) {</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// ...</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; }</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><b class="">Detailed design</b></div><div class=""><br class=""></div><div class="">TBD</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><b class="">Impact on existing code</b></div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><b class="">Alternatives considered</b></div><div class=""><br class=""></div><div class="">TBD</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I would really appreciate your comments and suggestions, and I'd certainly be willing and committed to completing this proposal based on community feedback.</div><div class=""><br class=""></div><div class=""><div class="">Thanks!</div><div class=""><div class="">Scott</div><div class=""><br class=""></div><div class="">--</div><div class="">Scott Gardner</div><div class=""><a href="http://scotteg.com/" class="">http://scotteg.com</a></div></div></div></div></div><div class=""><br class=""></div><div class=""><br class=""></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>