<div dir="ltr"><div><i>&quot;To me documentation plus the type signatures are generally enough. However I could probably still agree with you if mutating was also used in classes. What&#39;s the point of having it only on structures?&quot;</i></div><div><br></div><div>Because, structs ARE immutable by default. The mutating keyword says to holding variable to copy-change and re-assign the value type. You never notice the didSet called after mutation?</div><div><br></div><div><i>&quot;<span style="font-size:13px;line-height:19.5px">By the way, structures as value types (arguably) create some awkwardness and certainly add special cases to the language</span></i></div><div style="font-size:13px;line-height:19.5px"><i>1) `let`  and `var` aren’t just about reassignment anymore. It depends on the context: for classes it’s still about reassignment; for structures it’s about reassignment and mutability (well, also depending on whether the properties of the structure are `let` or `var` themselves).</i></div><div style="font-size:13px;line-height:19.5px"><i>2) the `mutating` keyword on protocol extensions is only there for structures and enums - and doesn’t even enforce them to actually mutate anything.</i></div><div><i><span style="font-size:13px;line-height:19.5px">3) the class specific protocol extensions.</span>&quot;</i></div><div><br></div><div><div>1) Its not true. Its just about the reassignment. But for value-types in automatic the process of copy-change and assign.</div><div>2) because only value types need this keyword. And the problem of do not enforce the mutation maybe can be a future improvement, it&#39;s not a big deal, you can propose this adjustment.</div></div><div>3) what&#39;s the problem here?</div><div><br></div><div><br></div><i>&quot;<span style="font-size:13px;line-height:19.5px">Good point, but I still think this is on a different class of problem because  1) it’s really hard to track where we were relying on value semantics before and adapt it to using classes and 2) the sort of bugs that would creep out wouldn’t probably be crashes but weird side-effects incredibly hard to track.</span>&quot;</i><div><br></div><div><div>Can you elaborate this? Does not appear a real world problem.</div><div>Change struct for class will always be a &quot;break change&quot;. Its not free of bugs in any language.</div><div><br></div><div><i>&quot;<span style="font-size:13px;line-height:1.5">--</span><span style="font-size:13px;line-height:1.5"> </span><span style="font-size:13px;line-height:19.5px">Integers are value types</span><span style="font-size:13px;line-height:1.5"> </span><span style="font-size:13px;line-height:1.5">--</span></i></div><div style="font-size:13px;line-height:19.5px"><i>Aren’t they also immutable?<span style="line-height:20px;font-size:small">&quot;</span></i></div><div style="font-size:13px;line-height:19.5px"><span style="line-height:20px;font-size:small"><br></span></div><div style="font-size:13px;line-height:19.5px"><span style="line-height:20px;font-size:small">yes....</span></div><div style="font-size:13px;line-height:19.5px"><span style="line-height:20px;font-size:small"><br></span></div><div style="font-size:13px;line-height:19.5px"><i><span style="line-height:20px;font-size:small">&quot;</span><span style="line-height:1.5">--</span><span style="line-height:1.5"> </span>Arrays are value types<span style="line-height:1.5"> </span><span style="line-height:1.5">--</span></i></div><div style="font-size:13px;line-height:19.5px"><i>Why? I would honestly like to know. I think all languages I’ve used in the past had arrays as reference types. Is it just because of equality? </i></div><div style="font-size:13px;line-height:19.5px"><span style="line-height:20px;font-size:small"><i>&quot;</i></span></div><div style="font-size:13px;line-height:19.5px"><span style="line-height:20px;font-size:small"><br></span></div><div><div>This ship sailed a long time ago.... This is a big feature in swift, on the old swift forum may you can see the role discussion about that.</div><div><br></div><div><div>Value type arrays are something with I miss in other languages.</div><div class="gmail_quote"></div></div><div><br></div><div><i>&quot;<span style="font-size:13px;line-height:1.5">--</span><span style="font-size:13px;line-height:1.5"> </span><span style="font-size:13px;line-height:19.5px">CGPoints are value types</span><span style="font-size:13px;line-height:1.5"> </span><span style="font-size:13px;line-height:1.5">--</span></i></div><div><i><span style="font-size:13px;line-height:19.5px">Other than digging into the documentation, how can we tell it has value semantics? We can’t just skim the code and understand it anymore - we have to dig into class/structure definitions to figure out whether each thing is a value or reference. And we’ll have to do it constantly because things that work with structures would be disastrous for classes.</span>&quot;</i></div><div><br></div><div>hu?  Just check if the type is a struct or a enum! So will be a value type. Whats the problem here?</div><div><br></div><div><i>&quot;<span style="font-size:13px;line-height:1.5">--</span><span style="font-size:13px;line-height:1.5"> </span><span style="font-size:13px;line-height:19.5px">Freedom from race conditions</span><span style="font-size:13px;line-height:1.5"> </span><span style="font-size:13px;line-height:1.5">--</span></i></div><div style="font-size:13px;line-height:19.5px"><i>Only accidental race conditions. Often memory is shared because it must be. Those are the tricky ones to solve.</i></div><div><i>&quot;</i></div><div><br></div><div>So, &quot;accidental&quot; are the name of most common bugs right? All bugs are &quot;accidental&quot;.... The same argument you can use for avoid Optionals.<br></div><div><br></div><div><i>&quot;<span style="font-size:13px;line-height:1.5">--</span><span style="font-size:13px;line-height:1.5"> </span><span style="font-size:13px;line-height:19.5px">Reference types as properties of structures</span><span style="font-size:13px;line-height:1.5"> </span><span style="font-size:13px;line-height:1.5">--</span></i></div><div style="font-size:13px;line-height:19.5px"><i>Why even allow it? Isn’t the whole point of structures to be used in small, simple cases? Allowing reference types inside opens up a can of worms with these “forReading/forWriting” methods…</i></div><div><i>&quot;</i></div><div><br></div><div>No, the whole point of structs are not to be used in small and simple cases, not on Swift, in swift um Swift are first class citizen and can be use for complex data structure, like Array and Strings. You can make a private shared buffer behind the scenes.<br></div><div><br></div><div><br></div><div>&quot;<span style="font-size:13px;line-height:19.5px">Finally, thanks for the link to the video Douglas. I hope I didn’t sound combative. It wasn’t my intention. Sadly I wasn&#39;t converted. Perhaps next year? :)</span></div><div>&quot;</div><div><br></div><div>FWIW: </div><div>Try this one: <a href="https://developer.apple.com/videos/play/wwdc2015-408/">https://developer.apple.com/videos/play/wwdc2015-408/</a> ( Protocol-Oriented Programming in Swift )</div><div><br></div><div>It explains (too) why structs are so important in Swift. Spoiler: Because its not a OO primary language.</div><div><br></div><div>Em sex, 25 de dez de 2015 às 15:47, Lino Rosa via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; escreveu:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 25, 2015 at 12:32 T.J. Usiyan &lt;<a href="mailto:griotspeak@gmail.com" target="_blank">griotspeak@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span><br><div><i><span style="line-height:1.5"><br></span></i></div></span><div>I don’t understand why we need the `mutating` keyword in the first place. Is it for readability? Right now the compiler knows when a function mutates a property and forces us to write `mutating`. Couldn’t it just fail compiling when try to call a mutation function but we’re not allowed?</div><div><br></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I strongly disagree with this sentiment. I agree that the compiler can figure it out without us in many cases but I appreciate knowing *explicitly* which parts of an API will mutate a value. It is helpful for both the vendor and consumer of the API to require that keyword.  </div></div><br></div></div>
</blockquote></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=fuWmDRE6-2FDdvdUHeLHruUfdigJaxz7nh99l6HfkulY-2Beyn9XwPPQruGX4TgHJFcuXltVM-2FkTQcvCcHxBkHRIaNmAxQpxPaGQzqFeyKqUVFcJcjKvCVrvyn8ESNA5N02UISmwtC-2BJsshdi-2BVj3iwjJpXqizkHWJgQGgqoIzAKW2-2BNyFkpMbu-2BAxN3cC5qM8XWVTr0gj7G-2FPWkpTMrWftm4426E15LiHLGJ-2BCcogwrB4E-3D" alt="" width="1" height="1" border="0" style="min-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">
_______________________________________________<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></div></div>