SE-0390: @noncopyable structs and enums

+1. This is an important feature that will bring the benefits of value semantics to cases where a resource must be cleaned up after its last use.


I don't love the term "copy", though. When I think of a copy, I think of things like copying a buffer — taking the contents of one buffer and duplicating them within another buffer. I don't think of things like doing atomic reference counting operations. This loading of the term "copy" will result in confusion in cases like this (once we have the copy operator):

1> let a = Array(repeating: 0, count: 512)
2> var b = copy a
3> b[2] = 1

It'll be difficult to explain to a beginner that the array's contents are not copied in line 2, but that they are copied in line 3.

Seeing that we chose the term "consume" instead of the more popular term-of-art "move" to avoid confusion, I think we should consider using a different term for "copy" as well.

Some possible replacements are:

  • clone (I believe Rust uses this term for a similar operation)
  • duplicate
  • recreate
  • replicate

Edit: changed a let to var in the code sample above, thanks tera!

4 Likes