Support of algebraic operations on dictionaries (was: ... sets)

Bert Freudenberg bert at freudenbergs.de
Sat Jun 16 13:45:35 UTC 2007


On Jun 16, 2007, at 13:53 , sig wrote:

> Another example of breaking protocol rules. Do you see any practical
> and good use in overriding #do: in Dictionary to iterate through list
> of values instead of associations by default? I don't. I'm serious.

Again - if that is really what you want, use a Set of Associations then.

Besides, your proposed change of Dictionary semantics would break a  
lot of code. I just tested this - even just accepting a method  
invokes Dictionary>>do:. You can't possibly be seriously suggesting  
that.

> I'm agree that Dictionary must behave as Collection at first place and
> only then as Set. But it isn't:
> TestClass >> isAdded: value to: collection
>   collection add: value.
>   ^ collection includes: value.
> --
> self isAdded: (a -> b) to: Dictionary new.    --- returns false
>
> Does it behaves correctly in this example?

No, because Dictionary wrongly inherits #add: from Set. E.g., #add:  
and #remove: surely should be symmetric, but see Dictionary>>remove:  
which is forbidden. #add: on a dictionary would only make sense if a  
default key was provided - like, in an OrderedCollection a new  
"default" index is added, too. To add something to a Dictionary use  
#at:put:. You need to provide a key. Having an #addAssociation: would  
be consistent with #associationAt: etc.

We both seem to agree Dictionary is inconsistent, it's a rather  
pragmatic hack instead of a clean design. I don't really see a need  
to completely revamp it, but if we do so, I'd strongly advocate  
compatibility with current usage.  Not inheriting from Set anymore at  
least would spare us discussions like this in the future. It *is*  
confusing to newcomers, so much is sure.

>> So please, to get this discussion to a fruitful end, let's fix
>> Dictionaries, but not redefine their semantics to suit your specific
>> needs. Maybe using Nicholas' suggestion (which I find cleaner but has
>> potentially more severe consequences) or by patching up Dictionary,
>> in this case by overriding #asSet.
>
> I understand your position. If you consider Dictionary as collection,
> lets fix it conform to Collection first. :)

Agreed.

Anyway, I think I've made my position clear. Lets hear what others  
think.

- Bert -





More information about the Squeak-dev mailing list