<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="">On Dec 30, 2015, at 5:38 PM, Kevin Ballard via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<title class=""></title>
<div class=""><div class="">I strongly recommend either making the context get explicitly used in the subsequent animations (e.g. `context.animation(...)` instead of just `animation(...)`) or giving it an explicit scope (e.g. `withAnimationContext(speed: 1.0, bounciness: 1.0) { ... }`). Having the presence of a stack value influence behavior is a great way to cause maintenance issues later on.<br class=""></div>
<div class=""> </div>
<div class="">-Kevin Ballard</div>
<div class=""> </div>
<div class="">On Wed, Dec 30, 2015, at 10:10 AM, Ollie Wagner via swift-evolution wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">I'm using the lifetime of a variable to push and pop a context in an animation system that I'm writing. I'm interested in using a pattern like:<br class=""></div>
<div class=""> </div>
<div class=""><span class="font" style="font-family:Menlo">func doAnimations() {</span><br class=""></div>
<div class=""><span class="font" style="font-family:Menlo"> AnimationContext(speed: 1.0, bounciness: 1.0)</span><br class=""></div>
<div class=""><span class="font" style="font-family:Menlo"> // do some animations using these options</span><br class=""></div>
<div class=""><span class="font" style="font-family:Menlo">}</span><br class=""></div>
<div class=""> </div>
<div class="">But today, the value returned by <span class="font" style="font-family:Menlo">AnimationContext(speed:bounciness:)</span> gets deinitted immediately.<br class=""></div>
<div class=""> </div>
<div class="">I've come to desire using such a pattern after living with this for a while:<br class=""></div>
<div class=""> </div>
<div class=""><span class="font" style="font-family:Menlo">AnimationContext(speed: 1.0, bounciness: 1.0) {</span><br class=""></div>
<div class=""><span class="font" style="font-family:Menlo"> // do some animations using these options<span style="white-space:pre;" class=""></span></span><br class=""></div>
<div class=""><span class="font" style="font-family:Menlo">}</span></div></blockquote></div></div></blockquote><blockquote type="cite" class=""><div class=""><div class=""><blockquote type="cite" class=""><div class=""> </div>
<div class="">But I don't like it because it contributes heavily to rightward drift (a user of this API might want to change the options multiple times), and gets hard to parse when nested in the many other language constructs that create a scope using brackets.<br class=""></div></blockquote></div></div></blockquote><div><br class=""></div><div>Not sure how contrived your code example is but in the given example wouldn’t just chaining off of AnimationContext solve rightward drift?</div><div><br class=""></div><div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class="">AnimationContext<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(speed: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1, </span><span style="color: rgb(0, 0, 0);" class="">bounciness</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">: 1</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) {</span></div><p style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; min-height: 15px;" class=""> ...<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo;" class="">}.changeSpeed(to: <font color="#272ad8" class="">2</font>) {</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo;" class=""> ...</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo;" class="">}</div><div class=""><br class=""></div></div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><blockquote type="cite" class="">
<div class=""> </div>
<div class="">So — would it be reasonable to suggest that we have some keyword(s) preceeding an initializer that allows a value to stay alive and/or not warn if it winds up going unused? The current behavior in Swift has obviously been considered, so please feel free to tell me if this is a Very Bad Idea. I'm still learning!<br class=""></div>
<div class=""> </div>
<div class="">- Ollie<br class=""></div>
<div class=""><img style="height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-bottom:0px !important;margin-right:0px !important;margin-left:0px !important;padding-top:0px !important;padding-bottom:0px !important;padding-right:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/b29cb67746ef1a8a90140bfcd35c5140d8485a7cf1d9a3e60d215eb45e604e6a/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3148765176786c673171614a7d2236454230345272776e436454637668357c675248374a57415051654f6271547849307a487a69426b453d6a7973665c47374151326051656839415644523652316a4e436c444a796c6f627a464749576b6577794a503a7d2232446452415b4734524131534d22364a6f6376613678503a6f4663326b616e6942653a6871576677797979674256535b4b6266414275327144735e4c6839685e6932627a4676723f6f65454e67545d22324564593f607f4965733946327d223249575a473874374a79654b444c42754a685652314668667076415d23344d23344/open" class=""><br class=""></div>
<div class=""><u class="">_______________________________________________</u><br class=""></div>
<div class="">swift-evolution mailing list<br class=""></div>
<div class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""></div>
<div class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div>
</blockquote><div class=""> </div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1Ry8ov4zuU66O51YNcjYWf4knmDCcYkavDpVSeINLvsAW5QVYhpUskSH3ry9J-2BAIHDbA0eKPV4Q8wxIwD7lJF3f7xLPekos1eMYRMXzPrn5Fw0wgKCj-2F-2F96Bwj2qggTWIE5hRYDwQj3xa5AWQuh-2FISHM3C1x19FGzcP1laDFvzBPjE5PhldhKMklnx-2FjLgztHnHYSvYZ2AgpX-2Bv3Q7F5hw-3D-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" 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>