associative arrays: iteration is finally here

Leandro Lucarella llucax at gmail.com
Thu Oct 29 11:16:02 PDT 2009


Andrei Alexandrescu, el 29 de octubre a las 12:33 me escribiste:
> Bill Baxter wrote:
> >>I think bool remove(key) is better than all other designs suggested so far.
> >
> >I agree with the folks who say it's error-prone.  I can just see
> >myself now removing a key I know is in the dictionary and being
> >baffled when my program fails somewhere later on because I typed
> >aa.remove("theKey") when it should have been aa.remove("thekey").  I
> >knew it was there so I didn't want to clutter up my code with a check
> >for it.
> 
> I don't find this reasonable. If you know removal must have
> succeeded, just type enforce(aa.remove("theKey")). I don't think

I don't agree, this is like saying you should bound-check every array
access. I think it's nice to have safety by default. If you are expecting
to have an error, you will be extra careful to spell the key correctly.
This should cover the cases where you are distracted and not expecting any
errors.

I think the check could be done in non-release mode only though, just
like bound checking.

> that's the overwhelmingly common case though, and if it's, say,
> about 50/50, then it's much more sensible to have a non-throwing
> primitive than a throwing one. And it looks like defining two
> primitives just to save a call to enforce is not a good design.

This is one case where I think practicality beats purity, because the
whole point of throwing an exception is for the cases you don't expect it
to fail. Again, think of array bounds, you can force the programmer to add
lots of enforce() in the code and remove bound checking from the compiler.

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
EXPOSICION INTERNACIONAL DE INODOROS
	-- Crónica TV



More information about the Digitalmars-d mailing list