Re:Python dicts are now ordered
by kingdomcome50 on Monday February 10, 2020 @05:22PM
(#22294057)
I guess my reasoning is that:
$arr = []
doesn't appear to be initializing to any capacity. So that after:
$arr[2] = "two"
I would expect:
count($arr) === 1
And honestly, sure. A language could be designed to pad the array with empty values if you specify an index greater than the upper bound (or lesser than the lower bound). I believe a sibling mentioned matlab did something like that.
But is that really better behavior or just different behavior? I don't really see an important difference. My point was that the criticism was fairly weak. PHP, indeed, has a very useful abstraction in its concept of "array". Most of the hate should be directed at the name, not the construct.
Well, there's no reason a language could not initialize an empty array to some initial capacity, either on declaration or when you add an indexed element.