<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=""><div><blockquote type="cite" class=""><div class="">On Sep 18, 2017, at 9:47 AM, Adam Kemp &lt;<a href="mailto:adam_kemp@apple.com" class="">adam_kemp@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">Would it be possible to actually fix this? That is, make the code covered by the `await` evaluate synchronous subexpressions first, such that the code sample above is equivalent to this?</div><div class=""><br class=""></div><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>@IBAction func buttonDidClick(sender:AnyObject) {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; beginAsync {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>let $temp1 = self.resizeSwitch.isOn</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>let $temp2 = await downloadImage()</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; let image = await processImage($temp2, resize: $temp1)</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; displayImage(image)</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; }</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div></div></div></div></blockquote></div><br class=""><div class="">That violates the defined order of evaluation for function arguments.</div></div></div></blockquote><div><br class=""></div><div>I understand that, but this order of evaluation was designed before we had `await`. I'm suggesting that, now that we do, we should change the order so that synchronous subexpressions are evaluated before asynchronous ones.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class="">You could also write code in which the (async) first argument function call has side effects that alter the result of the second argument expression. I’m not saying that’s good code, but it’s possible, and the language defines the order of evaluation so that code like that will have a predictable behavior.</div></div></div></blockquote></div><div class=""><br class=""></div><div class="">You could write something like that, but as you say, that's not necessarily good code. Honestly, I don't think you can write good code that depends on one part of an expression being evaluated after an async call in another part of the expression completes.</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;  "><div class=""><div style="font-size: 12px; " class="">--&nbsp;</div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>

</div>
<br class=""></body></html>