This would defeat @noescape and any generic return type we might want to add to dispatchSync.<br><div class="gmail_quote"><div dir="ltr">On Thu, May 12, 2016 at 11:52 AM Hooman Mehr via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>Exactly: I also consider synchronous dispatch a special case not worthy of sacrificing a better name (`dispatch`) for it. I prefer to have a single `dispatch` as the main function name. Here is my proposed modified signature based on the <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md" target="_blank">proposal</a>:</div><div><br></div><div><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal"><span style="color:rgb(167,29,93)">class</span> DispatchQueue <span style="color:rgb(167,29,93)">:</span> DispatchObject {
<span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">dispatch</span>(synchronous: Bool, work: <span style="color:rgb(167,29,93)">@convention</span>(block) () <span style="color:rgb(167,29,93)">-></span> <span style="color:rgb(0,134,179)">Void</span>)
</pre></div></div></div><div style="word-wrap:break-word"><div><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal"><span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">dispatch</span>(
group: DispatchGroup? <span style="color:rgb(167,29,93)">=</span> <span style="color:rgb(0,134,179)">nil</span>,
qos: DispatchQoS <span style="color:rgb(167,29,93)">=</span> <span style="color:rgb(167,29,93)">.</span>unspecified,
flags: DispatchWorkItemFlags <span style="color:rgb(167,29,93)">=</span> [],
work: <span style="color:rgb(167,29,93)">@convention</span>(block) () <span style="color:rgb(167,29,93)">-></span> <span style="color:rgb(0,134,179)">Void</span></pre></div></div></div><div style="word-wrap:break-word"><div><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal">)
}
queue<span style="color:rgb(167,29,93)">.</span> dispatch(group: group) {
<span style="color:rgb(0,134,179)">print</span>(<span style="color:rgb(24,54,145)"><span>"</span>Hello World<span>"</span></span>)
}
queue<span style="color:rgb(167,29,93)">.</span>dispatch(synchronous: true) {
<span style="color:rgb(0,134,179)">print</span>(<span style="color:rgb(24,54,145)"><span>"</span>Hello World<span>"</span></span>)
}</pre><div><br></div><div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">In the above synchronous variant, passing synchronous flag as false simply delegates to async function. This saves us from having to use a name like dispatchSync(). </div></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Actually, I currently have my own wrapper for libdispatch that works in this way. My wrapper also unifies more of the API under the same `dispatch` function with more optional parameters. For example, `apply` functions are also handled with `dispatch` function. It will iterate if `iterations:` optional parameter is specified and so on. I find it very convenient to use and the resulting code is very clear and readable.</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">I know, this goes further than importing the existing API, but concurrency API has such a profound impact on the overall style and readability of code that it is worth going even further than what proposal suggests to get a really clear and readable API.</div></div></div></div><div style="word-wrap:break-word"><div><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Hooman </div></div></div></div><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On May 12, 2016, at 11:16 AM, Thorsten Seitz via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div style="word-wrap:break-word">dispatch() and dispatchSync() would be my preference as asynchronous dispatch is the point of GCD and synchronous dispatch is a special case and therefore I think the visual asymmetry is an advantage.<div><br></div><div>-Thorsten</div><div><br></div><div><br><div><div><blockquote type="cite"><div>Am 12.05.2016 um 20:10 schrieb James Dempsey via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>:</div><br><div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On May 11, 2016, at 8:02 PM, Ricardo Parada <<a href="mailto:rparada@mac.com" target="_blank">rparada@mac.com</a>> wrote:</div><br><div><div dir="auto"><div><br><br>For synchronously and asynchronously how about the adverbs before the verb:</div><div><br></div><div>syncDispatch()</div><div>asyncDispatch()</div></div></div></blockquote><div><br></div><div><br></div><div>I think with the abbreviation ‘sync’ it’s very easy to read ‘sync’ as a verb and dispatch as a noun.</div><div><br></div><div>i.e. I’m going to sync up with you about our plan</div><div>i.e. I received a dispatch from headquarters</div><div><br></div><div>I would be very fine with</div><div><br></div><div>dispatchAsync() and dispatchSync() as method names.</div><div><br></div><div><br></div><div><br></div><blockquote type="cite"><div><div dir="auto"><div><br></div><div>?</div><div><br>On May 11, 2016, at 10:50 AM, James Dempsey <<a href="mailto:dempsey@mac.com" target="_blank">dempsey@mac.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div><blockquote type="cite"><div style="word-wrap:break-word"><div>So maybe that will conform to the API naming guideline? Or would the verb have to be in the base name of the func?</div></div></blockquote></div><div><div style="word-wrap:break-word"><div><br></div><div>It seems from the guidelines that the intent is for the verb to be in the base name of the func, especially since there is another set of guidelines for naming function parameters.</div><div><br></div><div>In general the other methods in the proposal are verbs (perform(), notify(), wait(), cancel(), etc.)</div><div><br></div><div>At least for me, not including a verb makes the API read like the sentence “The dog quickly”. This wasn’t so bad in the C API, because you could read the word ‘dispatch’ as the verb.</div><div><br></div><div><br></div><div>Looking at the current GDC API, it does seem like dispatching synchronously is the rare and special case.</div><div><br></div><div>Could there be just a single dispatch() method, with async as a flag with a default value of true?</div><div><br></div><div>It might be a little ugly because most of the other parameters of the proposed asynchronously() method would not apply in the sync case.</div><div><br></div><div>James</div><div><br></div><div><br></div></div></div><br><div><blockquote type="cite"><div>On May 11, 2016, at 7:14 AM, Ricardo Parada <<a href="mailto:rparada@mac.com" target="_blank">rparada@mac.com</a>> wrote:</div><br><div><div style="word-wrap:break-word">Jacob Bandes-Storch suggested:<div><br></div><div><font face="Consolas">synchronously(execute work: …)</font></div><div><br></div><div>So maybe that will conform to the API naming guideline? Or would the verb have to be in the base name of the func?</div><div><br></div><div>Or perhaps:</div><div><br></div><div><div><font face="Consolas">synchronously(dispatch work: …)</font></div><div><div><font face="Consolas">asynchronously(dispatch work: …)</font></div></div><div><br></div><div><br></div><div><br></div><div><blockquote type="cite"><div>On May 11, 2016, at 9:32 AM, James Dempsey via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div>The method names</div><div><br></div><div><span style="white-space:pre-wrap">        </span>synchronously()</div><div><span style="white-space:pre-wrap">        </span>asynchronously() </div><div><br></div><div>are both adverbs, not noun phrases or verb phrases.</div><div>These methods have side effects, so each name should have a verb in it to make it a verb phrase.</div><div><br></div><br><div><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Since these are the methods where you actually dispatch a block into a queue</div><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">dispatchSynchronously()</div><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">dispatchAsynchronously()</div><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">would include the verb in the name of the methods.</div><br></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div></blockquote></div></div></blockquote></div><br></div>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></div>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">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>
</blockquote></div>