Indexing access for Lists and Maps considered harmful?

Joseph D. Darcy Joe.Darcy at Sun.COM
Mon Jun 22 22:46:25 PDT 2009


My current preference is to keep a simple desugaring of the indexing 
operators into method calls.  While collection usage would certainly be 
a common case, there are probably other to-be-written APIs that would 
benefit from the translation into method calls.

-Joe

Reinier Zwitserloot wrote:
> 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