News for hackers. Stuff that matters.
Re:Impressions of Rust as a Swift Developer: Memory Management by twic on Wednesday March 11, 2020 @07:43AM (#22544936)
> In Swift, value types have what's called "copy-on-write" behavior, which means every time a value type is written to a new variable, or passed to a function, a copy is made.

That isn't copy-on-write, that's just copy.

Does "copy-on-write" mean that Swift behaves as if it is doing this, but actually defers copies where it can, passing references to the original until a function needs to modify its 'copy'?

Rust lets you do this explicitly via the Cow smart pointer:

https://doc.rust-lang.org/std/borrow/enum.Cow.html

But it's not transparent, and it's not used a lot in practice.

Re:Impressions of Rust as a Swift Developer: Memory Management by monocularvision on Wednesday March 11, 2020 @10:35AM (#22546168)
The author is wrong in their description. Some value types in Swift (like the standard library collection types like Array<T>) are value types with copy-on-write behavior. Until modified, copies of the Array are not made.

That copy-on-write functionality must be purposely implemented in the type and is not something provided automatically in Swift.

Re:Impressions of Rust as a Swift Developer: Memory Management by skohan on Wednesday March 11, 2020 @01:12PM (#22547595)
Thanks for the feedback, I was conflating copying with copy-on-write. I have made a correction in the article.