Indexing access for Lists and Maps considered harmful?
Reinier Zwitserloot
reinier at zwitserloot.com
Mon Jun 22 14:51:00 PDT 2009
I agree that the expression "map[c] = d" returning the OLD value of
map[c] (e.g. usually null) is unacceptable behaviour, but I think this
propsoal would fare just fine if this form of operation is defined to
return void and not 'd', in order to avoid confusion. There are many
code bases that never use pass-through assignment, and the workaround
(write it out...) is by definition not more boilerplate and noise than
what we have now.
I do lean slightly to preferring the expression to return 'd', and not
void, nor 'old mapping of c'.
--Reinier Zwitserloot
On 2009/22/06, at 22:40, Lawrence Kesteloot wrote:
> On Mon, Jun 22, 2009 at 12:19 PM, Joseph D. Darcy<Joe.Darcy at sun.com>
> wrote:
>> map["a"] = map["b"] = "c";
>>
>> the new value for key "a" would be the old mapping of "b" and not
>> necessarily "c" because a call to the put method returns the old
>> value.
>
> There is no way that:
>
> map["b"] = "c"
>
> can return anything other than "c". Returning the old value or
> returning void would violate 40 years of C-based expectations
> (including the identical construct in the STL). It must either return
> "c" or not be implemented at all.
>
> Lawrence
>
More information about the coin-dev
mailing list