Personally I like x
the most, aesthetically, because it's immediately clear what a "[5 x Int]
" is, in a way that isn't matched by any of the alternatives. Perhaps because of the resemblance with the "⨉" operator in matrix notation, I think I subconsciously read [5 x Int]
as a 5 ⨉ 1 vector of Int
-typed elements (which is exactly what it is), or 5 "dimensions" of Int
.
However, I find it rather confusing when combined with the Future Direction of extending it to literal initialization, because I also inevitably see [5 x 99]
as "a matrix of 5 rows and 99 columns", not as "a row of 5 values all being 99". I don't really see a way to use the same symbol to convey both dimensionality and repeated values, but x
would be particularly confusing in that dual role.
IMO the type sugar is enough here:
let x = [5 x Int](repeating: 99)
And adding the extra sugar to elid repeating
can only cause confusion. Also, I suspect initializing to zeros (or some other default value) is going to be by far the most popular thing to do, and I wonder if that case wouldn't be better served by a static extension:
let fiveZeros: [5 x Int] = .zero
Rather than needing to come up with a new syntax sugar for arbitrary repeated values that can be used everywhere.
Without considering that future direction, I like x
(as proposed) the most, then
or ;
(*
doesn't really suggest dimensionality to me, even though I see why some people prefer it over x
).
However, if we absolutely must use the same symbol for both "meanings", then I'd suggest explicitly trying to drop that association with "times" or "many" mentioned in the Alternatives Considered as a desirable trait:
[5; Int]
is what Rust uses, but appears to have little association with "times" or "many". Similarly other arbitrary punctuation e.g. ,
or /
or #
.
For which either
, ;
or of
would be probably fine.