<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 class="">The current choice is that if you need pass-by-value semantics, you use a struct; if you need pass-by-reference semantics, you use a class. This is almost only relevant when structs are mutable: the only semantic difference between a struct and a class is that mutating a struct won't have an impact on the original. If structs were immutable, there would be absolutely no distinction between a struct and a read-only class. In my opinion, immutable structs would make the choice much more ambiguous than it is right now.</div><div class=""><br class=""></div><div class="">Changing this would have a major impact. Arrays, dictionaries, sets and strings are all pass-by-value right now. It would be a massively breaking change to make them plainly immutable or to make them reference types. It would also throw a wrench into C interop, which is critical for Swift to succeed in a non-ObjC environment (like Linux).</div><div class=""><br class=""></div><div class="">I personally don't see a problem with the current semantics and I don't like the impact, so I'm not in favor of it.</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Grande'; 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; ">Félix</span>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Le 23 déc. 2015 à 10:44:49, Lino Rosa via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I believe the language would be improved by making structures immutable.</div><div class=""><br class=""></div><div class="">1) The choice between classes and structures isn’t clear right now. If structures were immutable it would be natural to use them as value objects.</div><div class=""><br class=""></div><div class="">2) Refactoring a mutable structure into a class when it’s being passed around multiple threads removes the by-value semantics seamlessly. The resulting mutable class isn’t thread-safe.</div><div class=""><br class=""></div><div class="">2.1) Even when passed around a single thread, the resulting class would be passed by reference, so any mutations would have unintended consequences.</div><div class=""><br class=""></div><div class="">3) We could probably remove some syntax: `mutating` keyword and variable parameters. Also the `var` keyword before a structure could be used to denote reassignment (not mutability), just as it does with classes.</div><div class=""><br class=""></div><div class="">Of corse I might not be seeing the whole picture, so please weigh in.</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=iRI3beHTe3UxYAHTlV3lA38zIPfHMhyuRzgTmGKV6k7xFNWD-2B-2F8QV2sgTfFP6Lxy-2BNs7KLXsGLhHLpVYlRSxeka2x3NQYeGiRuDmrqlnhpqaydNvgNwNkSPDYMk8jZ5CNAC2xKYCgTD1EZYWb-2FwXhVa9VeaU-2BANcNJsBog198Hhv2tlQJxj-2FkcIrwggD-2BS5HfExzfYh4TQzO7xfoWQvVftUc4ECww5txvn97jP9ctE4-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="">
_______________________________________________<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>