delete hash[key] deprecated???
Stewart Gordon
smjg_1998 at yahoo.com
Sat Jul 19 05:39:18 PDT 2008
"Max Samukha" <samukha at voliacable.com.removethis> wrote in message
news:d85384p9e1heua1f8f6vn2cesd9cosjlrc at 4ax.com...
> On Fri, 18 Jul 2008 22:27:16 +0100, "Stewart Gordon"
> <smjg_1998 at yahoo.com> wrote:
>
>>"Max Samukha" <samukha at voliacable.com.removethis> wrote in message
>>news:9d2r74tuopl0dt05sgnkagss4gu4824k9m at 4ax.com...
>><snip>
>>> If 'remove' was modified to return the removed value, more compact
>>> syntax would be possible:
>>>
>>> delete hash.remove("x");
>><snip>
>>
>>And what would remove do if the key is already not in the AA? Return
>>ValueType.init? Throw an exception?
>>
>>Stewart.
>
> Three options:
>
> 1. Throw an assert exception if the program was built with a debug
> switch
And do what if the program wasn't built with a "debug switch"? Moreover, I
personally think that debug switches should be saved for programmer-defined
debug code.
> 2. Always throw an exception
> 3. Make 'remove' return a pointer to the value
And so if the key isn't present, return null. Hmm.... I guess it would be
the programmer's responsibility not to keep lots of these pointers alive and
thereby prevent the AA nodes from being GC'd. Hmm....
> 4. Continue silently
But .remove has to return something. So how is this possible?
> I prefer the first option. Option 4 (current semantics) is the least
> acceptible, in my opinion.
Hang on ... is 4 meant to be an option under the premise that we want
.remove to return the removed value, or the option of not implementing this
feature at all?
Stewart.
--
My e-mail address is valid but not my primary mailbox. Please keep replies
on the 'group where everybody may benefit.
More information about the Digitalmars-d-learn
mailing list