<html><head></head><body><div>Well, you could actually have something like this now, and use whether the returned result was used or not to know if was a mutating or nonmutating method or not.<br><br><div class="acompli_signature">Patrick</div><br></div><br><br><br>
<div class="gmail_quote">On Fri, Apr 22, 2016 at 4:53 AM -0700, "James Campbell via swift-evolution" <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br>
<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="3D&quot;ltr&quot;">
<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">What if we had a concept similar to errors and try ?&nbsp;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">Given this function:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">func sort() -&gt; Self {</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">}</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">mutating sort() -&gt; Self {</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">}</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">If a developer calls:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">array.sort()</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">It will sort a copy of that array, in order to sort in place the developer must confirm the mutation like so:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">mutate array.sort()</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:#000000">This will then call the mutating version of sort :)</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">







<p><b><font color="#cc0000">___________________________________</font></b></p><p><b>James⎥Chief Of Fun</b></p><p><b><font color="#cc0000"><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>⎥<a href="http://supmenow.com" target="_blank">supmenow.com</a></font></b></p><p><b><font size="2">Sup</font></b></p><p><b><font size="2">Runway East
</font></b></p><p><b><font size="2">10 Finsbury Square</font></b></p><p><b><font size="2">London</font></b></p><p><b><font size="2">
EC2A 1AF&nbsp;</font></b></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On 22 April 2016 at 12:31, Haravikk via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is why I mentioned Xcode; while we can have ampersand as a language feature for marking such things explicitly (i.e- developer consents to doing it), we could also just have Xcode highlight inout parameters and mutating methods differently, but would these represent the same explicit “I know that what I’m doing here will have side-effects” impact (especially if other IDEs add Swift support but don’t do this).<br>
<div class="HOEnZb"><div class="h5"><br>
&gt; On 22 Apr 2016, at 11:54, Vladimir.S via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; From one point of view, it will be really awesome if we'll have some kind of 'marker' for mutating methods so we can clearly see in code if that method changes the instance(just like we all agree that we must specify &amp; for inout parameter).<br>
&gt;<br>
&gt; From other point of view, this will add a much more noise(and typing) in code as we often(in most cases?) use mutating methods. Have a code with a huge number of &amp; symbols(or other) in it - not the best thing.<br>
&gt;<br>
&gt; I don't see how we can unite both points.<br>
&gt;<br>
&gt; On <a href="tel:22.04.2016%2010" value="+12204201610">22.04.2016 10</a>:00, Tyler Cloutier via swift-evolution wrote:<br>
&gt;&gt; If I recall correctly there was a thread with a similar idea which instead<br>
&gt;&gt; would create a new operator for mutation or a new way of method invocation,<br>
&gt;&gt; such that mutating methods would be called with &amp;. or something similar. e.g.<br>
&gt;&gt;<br>
&gt;&gt; foo&amp;.add(5)<br>
&gt;&gt;<br>
&gt;&gt; I think the consensus was that that was not a particularly familiar syntax<br>
&gt;&gt; and it would add a decent amount of noise.<br>
&gt;&gt;<br>
&gt;&gt; There may have also been some issues with the grammar, I can't recall.<br>
&gt;&gt;<br>
&gt;&gt; On Apr 21, 2016, at 11:40 PM, Krishna Kumar via swift-evolution<br>
&gt;&gt; &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> &lt;mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt; Hey<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I think adding “&amp;” to methods will reduce the readability of the code.<br>
&gt;&gt;&gt; Also, keyword “mutating” makes it super clear and readable that my method<br>
&gt;&gt;&gt; is mutating the values.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; 1. mutating func add(value: Double){…}<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; 2. func add&amp;(value: Double){…}<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I think it’s easy to skip the information encoded into the 2nd function<br>
&gt;&gt;&gt; which is this function is mutating a value as compared to 1st. When I<br>
&gt;&gt;&gt; read 1st function I start reading with keyword “mutating” making its<br>
&gt;&gt;&gt; intentions clear to me.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Also, it might become a symbol nightmare with following type signature of<br>
&gt;&gt;&gt; a function-<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; func nightmare&amp;(title: String?) -&gt; String? -&gt; String?{…}<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I can see the advantage of using “&amp;” when calling a function. It makes<br>
&gt;&gt;&gt; clear at the call site that this method is mutating but still I don’t<br>
&gt;&gt;&gt; find eliminating “mutating” a good step for the reasons mentioned above.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Maybe we can think of some better solution.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Thanks<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; -Krishna<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On Apr 21, 2016, at 10:38 PM, Daniel Steinberg via swift-evolution<br>
&gt;&gt;&gt;&gt; &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> &lt;mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;&gt; wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> &lt;mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; swift-evolution mailing list<br>
&gt;&gt;&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a> &lt;mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;<br>
&gt;&gt;&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; swift-evolution mailing list<br>
&gt;&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt;&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
&gt;&gt;<br>
&gt; _______________________________________________<br>
&gt; swift-evolution mailing list<br>
&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>
</div></div></blockquote></div><br></div>

</div>

</blockquote>
</div>
</body></html>