On Mar 25, 2007, at 4:30 PM, Theodore H. Smith wrote:

>>>> On Mar 25, 2007, at 10:32 AM, John Kubie wrote:
>>>>
>>>>>
>>>>> On Mar 25, 2007, at 9:49 AM, Charles Yeomans wrote:
>>>>>
>>>>>> What is it that you find confusing about the Dictionary  
>>>>>> interface?
>>>>>
>>>>> The first awkwardness is the apparent necessity to test for the
>>>>> existence of a key before getting the key-value combination
>>>>> Next, the word "key" is not used when getting a value associated
>>>>> with
>>>>> a key.
>>>
>>> ElfDataDictionary doesn't impose this. You can just get value and if
>>> it doesn't exist, nil is returned.
>>
>>
>> But a REALbasic Dictionary allows one to store anything as a value,
>> including nil.  That leaves no magic value to return when no entry
>> with the specified key exists.  Raising a KeyNotFoundException is
>> then the best response.
>
> It's not the best response. I don't see how it is. In RB you do this:
>
> if dict.HasKey("bla") then
> value = dict.value("bla")
> else
> value = NewBla
> dict.value("bla") = Value
> end if

Actually, in Rb I'd do this:

if not dict.HasKey("bla") then
    dict.Value("bla") = NewBla
end if
value = dict.Value("bla")

>
>
> With ElfData it's this:
>
> value = dict.value("bla")
> if value = nil then
> value = NewBla
> dict.value("bla") = Value
> end if
>
> So it's the same, only faster and using less code.

But this misses my point, which is that the Rb Dictionary allows you  
to store Nil as a value, and so distinguishes between the cases
d has a key-value pair ("bla", nil) and d has no key-value pair with  
key = "bla".  Your class does not.  Either is a reasonable design  
choice, though I prefer the former.

Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to