Denis Kudriashov wrote
> Hi.
> 
> I just found that there is no WeakIdentityValueDictionary. But we have
> WeakValueDictionary, WeakKeyDictionary,  WeakIdentityKeyDictionary.
> 
> And to implement missing class I need to copy overrides from
> IdentityDictionary. And weak key dictionaries are implemented same way by
> duplicating code.
> 
> And generally identity collections are not much different from equal
> collections but they still duplicate a lot of code with little difference:
> #hash or #identityHash, #= or #==.
> 
> So I am wondering do we have alternative implementation with proper
> design?
> There are wishes to replace streams by XSteams. What about collections?
> 
> Best regards,
> Denis

I think design deficiencies of Pharo collections can be addressed with
traits.

Now Pharo has classes that mix:
- public interface of some type of collection
- implementation of numerous operations on collections (e.g. #collect:)
- implementation of collection's interface (e.g. #do:) 

Also different interfaces (iteration, mutation) are mixed together as well.

For example, Collection could be replaced by TIterable (iteration and other
methods from Collection that don't require mutation) and TCollection
(TIterable + adding and removing).
TIterable then can also be used for things like iterators/views/slices.

Similarly, SequenceableCollection -> TSequenceable (uses TIterable) and
TSequenceableCollection (uses TCollection + TSequenceable).
Dictionary -> TMap (uses TIterable) and TDictionary (uses TCollection +
TMap).

Perhaps also separate traits for immutable collections, that use iteration
traits and know how to make modified versions of themselves and how to
construct instance from stream.

For hashed collections, separate traits could be made for equality- and
identity-based collections. 
Perhaps they can even be made right now, without reorganizing whole
collections hierarchy - just by moving corresponding methods into them.



--
View this message in context: 
http://forum.world.st/Do-we-have-better-collections-design-library-tp4948936p4949268.html
Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.

Reply via email to