On Wednesday, 17 December 2014 at 13:13:43 UTC, Shachar Shemesh wrote:
It just seems like extra unneeded superfluous unnecessary redundancy.

It is somewhat important because storing a slice to a static array is a big problem:

int[] stored;
void func(int[] s) {
   stored = s;
}

void test() {
  int[12] a;
  func(a);
}

void main() {
   test();
   stored[] = 0; // just overwritten the stack!
}



Making you write the [] doesn't prevent this case, but it does at least remind you that a static array and a dynamic array aren't completely the same - it gives you a chance to look up the docs for func() and figure if it does store, dup it.


Though like bearophile said, the compiler DOES allow this implicit conversion at times, which has caused my bugs before. It is especially nasty when a char[x] gets implicitly converted to string due to this combining with the pure function -> immutable thing! There's a function in phobos that will convert like that and cause hidden crashes. Nasty.

Reply via email to