On Saturday, 9 April 2016 at 19:25:32 UTC, Uranuz wrote:
On Saturday, 9 April 2016 at 18:27:11 UTC, ag0aep6g wrote:
[...]
Another observation is illustrated with the foloving code:
http://dpaste.dzfl.pl/8d68fd5922b7
Because AA and arrays are not created before they were assigned
some value it leads to inconsistency in behavior. And will
produce unexpected and hidden bugs that is not good. It's not
very good side of D's array and AA. But classes could be also
affected by this *feature* (or bug, as you wish). So we must
always construct reference semantics types before passing them
to functions that will modify it. For classes it's obvious but
for AA and dynamic arrays is not.
Another solution is to pass reference types by *ref*. So you
will not have such bugs in implementation
I think that we need to add warning about such case in
documentation section:
https://dlang.org/spec/hash-map.html#construction_and_ref_semantic
in order to prevent this kind of mistakes in code.