Since the growable type in Swift is named Array
already, I don't think "Array
and Vector
have swapped meanings in Swift vs C++" is any harder to explain than "Array
is like a C++ vector
, and FixedArray
is like a C++ array
".
In fact, I'd argue that the latter is more confusing to explain to someone coming from C++. An analogous conversation could be:
— You shouldn't use array here. Array is a dyanically growable type like a C++ vector, it'll incur reference counting and bounds checking even though you know the size at compile time.
— OK. So what should I use?
— A fixed array.
— I thought you said not to use an array!
— No, you shouldn't use an array. A fixed array, on the other hand, is like a C++ array.
— Isn't fixed array an array?
— Well, on Swift both are arrays, but you want a C++ array, which is fixed array specifically, not array, which is like a vector.
— [surprised pikachu face]
Of course, it helps a lot to add formatting so "Array
" and "array" look like different things. But that's really hard to do on spoken conversations (or, more generally, when someone is being lazy with formatting).
Actually, a general concern I have with FixedArray
as a name (which I also raised during the pitch) is that it clashes with any statements of the form "arrays in Swift do X and Y..." because now you have to second-guess whether that statement applies to only the type Array
or any other "array" (like FixedArray
). This could be more palatable if the only difference between Array
and Vector
was the fixed length, but there's the inline aspect of it as well. Seems to me that Array
is fundamentally different enough from Vector
that these statements are going to create a lot of confusion.
FWIW, if anything, I think having the names swapped could help discoverability for those coming from C++: upon learning that Array
is a growable collection type in Swift, it's natural to then go on and search whether "Vector" exists and what it means in Swift, as that's the type C++ programmers would reach for when in need of a growable collection.