<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=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 21.08.2017 um 22:09 schrieb Karim Nassar via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:</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="">Thought about it in more depth, and I’m now firmly in the camp of: ‘throws’/‘try' and ‘async’/‘await' should be orthogonal features.&nbsp;I think the slight call-site reduction in typed characters ('try await’ vs ‘await’) is heavily outweighed by the loss of clarity on all the edge cases.</div></div></div></blockquote><div><br class=""></div>+1</div><div><br class=""></div><div>-Thorsten</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">—Karim</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Aug 21, 2017, at 1:56 PM, John McCall &lt;<a href="mailto:rjmccall@apple.com" class="">rjmccall@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Aug 20, 2017, at 3:56 PM, Yuta Koshizawa &lt;<a href="mailto:koher@koherent.org" class="">koher@koherent.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">2017-08-21 2:20 GMT+09:00 John McCall via swift-evolution&nbsp;<span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span>:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><span class="gmail-"><blockquote type="cite" class=""><div class="">On Aug 19, 2017, at 7:17 PM, Chris Lattner via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><div class="" style="word-wrap: break-word;"><blockquote type="cite" class=""><div class="">On Aug 19, 2017, at 8:14 AM, Karim Nassar via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="gmail-m_5864697011298285341Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word;"><div class="">This looks fantastic. Can’t wait (heh) for async/await to land, and the Actors pattern looks really compelling.</div><div class=""><br class=""></div><div class="">One thought that occurred to me reading through the section of the "async/await" proposal on whether async implies throws:</div><div class=""><br class=""></div><div class="">If ‘async' implies ‘throws' and therefore ‘await' implies ‘try’, if we want to suppress the catch block with ?/!, does that mean we do it on the ‘await’ ?&nbsp;</div></div></div></blockquote><blockquote type="cite" class=""><div class="" style="word-wrap: break-word;"><div class=""><br class=""></div><div class=""><font face="Menlo" class="">guard let foo = await? getAFoo() else { &nbsp;… &nbsp;}</font></div></div></blockquote><div class=""><br class=""></div><div class="">Interesting question, I’d lean towards “no, we don’t want await? and await!”.&nbsp; My sense is that the try? and try! forms are only occasionally used, and await? implies heavily that the optional behavior has something to do with the async, not with the try.&nbsp; I think it would be ok to have to write “try? await foo()” in the case that you’d want the thrown error to turn into an optional.&nbsp; That would be nice and explicit.</div></div></div></blockquote><div class=""><br class=""></div></span>try? and try! are quite common from what I've seen.</div></blockquote><div class="gmail_extra"><br class=""></div><div class="gmail_extra">As analogous to `throws` and `try`, I think we have an option that `await!` means blocking.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">First, if we introduce something like `do/catch` for `async/await`, I think it should be for blocking. For example:</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">```</div><div class="gmail_extra">do {</div><div class="gmail_extra">&nbsp; return await foo()</div><div class="gmail_extra">} block</div><div class="gmail_extra">```</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">It is consistent with `do/try/catch` because it should allow to return a value from inside `do` blocks for an analogy of `throws/try`.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">```</div><div class="gmail_extra">// `throws/try`</div><div class="gmail_extra">func foo() -&gt; Int {</div><div class="gmail_extra">&nbsp; do {</div><div class="gmail_extra">&nbsp; &nbsp; return try bar()</div><div class="gmail_extra">&nbsp; } catch {</div><div class="gmail_extra">&nbsp; &nbsp; ...</div><div class="gmail_extra">&nbsp; }<br class=""></div><div class="gmail_extra">}</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">// `async/await`</div><div class="gmail_extra">func foo() -&gt; Int {</div><div class="gmail_extra">&nbsp; do {</div><div class="gmail_extra">&nbsp; &nbsp; return await bar()</div><div class="gmail_extra">&nbsp; } block</div><div class="gmail_extra">}</div><div class="gmail_extra">```</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">And `try!` is similar to `do/try/catch`.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">```</div><div class="gmail_extra">// `try!`</div><div class="gmail_extra">let x = try! foo()</div><div class="gmail_extra"><div class="gmail_extra">// uses `x` here</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">// `do/try/catch`</div><div class="gmail_extra">do {<br class=""></div></div><div class="gmail_extra">&nbsp; let x = try foo()</div><div class="gmail_extra">&nbsp; // uses `x` here</div><div class="gmail_extra">} catch {<br class="">&nbsp; fatalError()<br class="">}</div><div class="gmail_extra">```</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">If `try!` is a sugar of `do/try/catch`, it also seems natural that `await!` is a sugar of `do/await/block`. However, currently all `!` in Swift are related to a logic failure. So I think using `!` for blocking is not so natural in point of view of symbology.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">Anyway, I think it is valuable to think about what `do` blocks&nbsp;for `async/await`&nbsp;mean. It is also interesting that thinking about combinations of `catch` and `block` for `async throws` functions: e.g. If only `block`, the enclosing function should be `throws`.</div></div></div></blockquote><div class=""><br class=""></div>Personally, I think these sources of confusion are a good reason to keep the feature separate.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">The idea of using await! to block a thread is interesting but, as you say, does not fit with the general meaning of ! for logic errors. &nbsp;I think it's fine to just have an API to block waiting for an async operation, and we can choose the name carefully to call out the danger of deadlocks.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">John.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><br class=""></div><div class="gmail_extra">That aside, I think `try!` is not so occasional and is so important. Static typing has limitations. For example, even if we has a text field which allows to input only numbers, we still get an input value as a string and parsing it may fail on its type though it&nbsp;actually&nbsp;never fails. If we did not have easy ways to convert such a simple domain error or a recoverable error to a logic failure, people would start ignoring them as we has seen in Java by `catch(Exception e) {}`. Now we have `JSONDecoder` and we will see much more `try!` for bundled JSON files in apps or generated JSONs by code, for which decoding fails as a logic failure.</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra"><div class=""><div class="gmail_signature">--<br class="">Yuta</div></div></div></div></div></blockquote></div></div></blockquote></div><br class=""></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=""></body></html>