4 ms·
That design is so awkward and clumsy I've never seen it used in production code. Worse, the user has to manually repeat the array length in the function call, a
by WalterBright 8y ago
That design is so awkward and clumsy I've never seen it used in production code. Worse, the user has to manually repeat the array length in the function call, a prime defect attracter.
- caf 8y agoNo argument on the awkwardness. The compiler should be able to diagnose incorrect array length passed at the call site, though?
- WalterBright 8y agoThat would require data flow analysis, which is a tricky thing to specify in the Standard, because how far should it go? For example, should it track values through functions like: int length(int len) { return len; } It would also mean no slices.
- a1369209993 8y agoThat's why I like the index type idea: [n] i = ...; int i1 = length(i); /* fine, but we dont know what i1 is */ [n] i2 = length(i); /* error, we assume length can return any int */ [n] i3 = length(i) < n else panic(""); /* also fine, and maybe we can optimize out the check, but we don't have to */