Vector, a fixed-size array

I think it makes sense to use a derived name when the new type is a slight modification of the concept, without challenging the core properties of the original type. StaticString is just a string known at compile time. This type still fits into most people's definition of what a string is. Remove an important enough property of String, and you get a completely different name, like Character (no longer a collection, but a single extended grapheme cluster) or ContiguousArray<CChar> (a collection of UTF8 characters instead of a collection of extended grapheme clusters).

So the question would be, is the ability of Arrays to grow a foundational part of what an "array" is in Swift? Or is it just a mere detail of the Array type in particular?

Several places in the documentation mention "array" (with a lowercase 'a') being a variable-size collection. To me this is a sign that the concept of array in Swift (and not the specific type Array) has been tied to it being a growable collection.

Plus, there's a huge pile of documentation that associates specific behaviors to "arrays" (like copy on write, heap allocation...) that wouldn't be true for FixedArray, simply because despite the superficial similarity, it's a fundamentally different type. Going beyond the state of the documentation today, one would always have to second-guess any statement of the form "arrays in Swift do X and Y..." (does it refer to arrays in general? or just Array?). The naming Vector would immediately address that uncertainty: Vectors are obviously not arrays. To this point, other languages seem to agree that these are different enough to warrant different names (even though C++/Rust had the names swapped).

FWIW, Rust's official documentation for array also has to clarify that it's a fixed-size array on the very first line. Similarly Rust's Vec also compares to array on its documentation (A contiguous growable array type [...]). It's not unreasonable to refer to other similar concepts when introducing a new concept. That doesn't mean that the explanation should be part of the name, otherwise dictionary-definition names would always prevail.

12 Likes