On Friday, 30 January 2015 at 07:37:07 UTC, Daniel Kozák wrote:
V Fri, 30 Jan 2015 01:08:30 +0000
bearophile via Digitalmars-d <[email protected]>
napsáno:
It helps avoid bugs like:
int[5] a = [1,2,4,5];
No, it makes more bugs possible
// this is compile error so its ok
int[MUST_HAVE_FIVE_ITEMS] a=[1,2,3,5];
// Error: mismatched array lengths, 5 and 4
// now this is compile error so its ok
int[$] a = [1,2,3,5]; // oops I miss one value
// but there is no error at compile time
If you already know that it needs to have 5 elements, don't use
`$`. Just like you wouldn't use `auto` if you want your variable
to be `long`.