auto arr = [1, 2, 3] should be a static array, not a GC allocated array

jfondren julian.fondren at gmail.com
Thu Jul 14 15:13:07 UTC 2022


On Thursday, 14 July 2022 at 14:37:34 UTC, ryuukk_ wrote:
> Then the compiler should tell them that it is a static array 
> and they should be explicit if they want to append
>
> Corner cases from clueless people shouldn't make the default 
> useless and misleading

Instead of the compiler telling those clueless people that their 
expectations were wrong, it's telling you that your expectations 
are wrong. And you want me to have no sympathy for people like 
that? I mean, if you really want that, OK:

It has to be one way or the other, and it's the way it is, and 
it's useful and it makes sense. Dynamic arrays are a 
high-convenience feature, so convenient you don't even have to 
care about their storage, and they're very naturally preferred by 
the convenience feature of not even having to say what type a 
value has.

Static arrays are still very nice in D, especially their array 
ops https://dlang.org/spec/arrays.html#array-operations , but 
they require extra care in more ways than this.


More information about the Digitalmars-d mailing list