associative arrays: iteration is finally here

bearophile bearophileHUGS at lycos.com
Thu Oct 29 04:15:54 PDT 2009


Andrei Alexandrescu:

> I'll make aa.remove(key) always work and return a bool that tells you 
> whether there was a mapping or not.

I think that's a small design mistake. In a high level language you want things to not fail silently. You want them to fail in an explicit way because programmers often forget to read and use return values.

So AAs may have two methods, "remove" and "drop" (Python sets use "remove" and "discard" for this). The "remove" can be the safer one and used by default in D programs (especially in SafeD modules, safety is in things like this too), that raises an exception when you try to remove a missing key. "drop/discard" is faster and silent, it removes the key if it's present, as you want.

Bye,
bearophile



More information about the Digitalmars-d mailing list