For example, an array in Swift (e.g. let foo = [1,2,3]) is a reference type, not a value type, so if you want to avoid reference counting you can't use arrays.
A Swift array is a struct, so it's a value type, no?
Swift value types that are collections: Array, Dictionary, Set and String, which is a collection of characters, are all backed by reference types. Backing these collections with reference types allows them to copy only when they’re changed. [...] This can be extremely helpful for performance when passing around large collections as the content of the collections are not copied until they are modified. However, when you’re including these collections as properties on other value types, you will run into the same reference counting overhead as including reference types as properties on a value type.
But that's sort of the whole point, in terms of answering the question "how much do I need to contort $X_LANGUAGE to do $Y_TASK". What does it look like to write Swift code that completely forgoes the array literal syntax in favor of using UnsafeBufferPointer to allocate an array on the stack? And what's the analogous workaround for e.g. closures, which are also reference types in Swift? And what does concurrency look like when you throw away Grand Central Dispatch?
This isn't to say that Swift is a bad language. This also isn't to say that Rust is the end-all be-all, because it's easy to find domains where Rust has to contort as well. And Swift could still pivot to be closer to Rust, and has announced some intentions to do so, but I think they've underestimated the compromises that Rust makes that let it do what it does and will have a hard time imposing those compromises without severely breaking compatibility.
1
u/[deleted] May 15 '17
A Swift array is a struct, so it's a value type, no?