Vector, a fixed-size array

+1 on the pitch; personally, I’m most excited to use the proposed type (alongside a similar one for matrices) for type-safe linear algebra.

The naming has been suficiently discussed, but I’ll add that the similarity between it and C++’s std::vector (or Rust’s std::vec) may not be a bad thing; hear me out. Swift arrays, being dynamically sized, are analogous to vectors in C++/Rust. So let’s imagine that we now do the opposite, naming the proposed Swift collection — which, being fixed-size, is analogous to C++/Rust arrays — Vector. Then it would be easy to explain to people coming from C++ or Rust, and for anyone to remember, that the meanings of “array” and “vector” are simply flipped between Swift and C++/Rust. But if we name the proposed type FixedSizeArray, then the explanation is that a Swift Array is a C++/Rust vector but a C++/Rust array is a Swift FixedSizeArray… awkward and less memorable.

As for whether the name Vector is “correct” from a math perspective: I think it absolutely is, and in fact is more appropriate for fixed-size collections than for dynamically-sized ones. In linear algebra, vectors of a given vector space do have a fixed number of dimensions/components: you can’t have a vector space containing both the 2D vector (2, 3) and the 3D vector (2, 3, 5). So the Swift type Vector<3, Double> would correspond to the 3-dimensional vector space over Double, while the dynamically-sized vector types of other languages don’t map to mathematical vectors at all.

And I can’t help but chime in on an even less important aspect, the name of the integer parameter. I wouldn’t want to spam the same bikeshedding on every pitch related to integer generic parameters, but the points here are especially relevant to the proposed type’s Count parameter.

8 Likes