[swift-evolution] Immutable Structures

Lino Rosa lino.aguiar.rosa at gmail.com
Wed Dec 23 09:44:49 CST 2015


I believe the language would be improved by making structures immutable.

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.

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.

2.1) Even when passed around a single thread, the resulting class would be
passed by reference, so any mutations would have unintended consequences.

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.

Of corse I might not be seeing the whole picture, so please weigh in.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151223/d18f2a19/attachment-0001.html>


More information about the swift-evolution mailing list