On 8/7/14, 3:57 PM, Andrei Alexandrescu wrote:
On 8/7/14, 10:35 AM, Puming wrote:
On Thursday, 7 August 2014 at 16:53:24 UTC, H. S. Teoh via Digitalmars-d
It's really just the .init value of null which causes odd behaviour with
empty AA's. Fun fact:

    void changeAA(int[string] aa) {
        aa["a"] = 123;
    }

    // Null AA:
    int[string] aa1; // null

    assert(aa1.length == 0);
    changeAA(aa1);    // no effect
for most of the new users the WAT part is actually here :-)

One function we could and should use is one that makes an AA that is
empty but not null. Right now one needs to use goofy methods such as
adding and then removing a key. -- Andrei

It still won't be intuitive for newcomers or for anyone not knowing that function.

I would invert it: declaring an associative array makes it non-null. Then you can choose, with a function, to initialize to null.

This would follow the principle of least surprise.

Reply via email to