Leandro Caniglia
Leandro Caniglia

Reputation: 14858

Why Associations are Magnitudes in Smalltalk?

I haven't checked many dialects yet (in Pharo Association is a subclass of LookupKey, which is a subclass of Magnitude) but I presume this is fairly common.

Isn't this definition counterintuitive? Associations usually take part in unordered collections and I don't think a Smalltalker ever takes into account that their keys could be sent #<=. What I would like to know is whether this is something we inherited from old implementations of Smalltalk and never bothered to challenge, or it is just me who am missing something. Bottomline: has anyone ever used this feature?

Upvotes: 3

Views: 177

Answers (1)

blabla999
blabla999

Reputation: 3200

I don't think that Dictionary needs that; all it needs are = and hash.

However, you often want to get a list of associations and sort them later (eg. to show them in some sorted list). Then, it is nice to have an order defined already.

And the cost is only a "<" method in Association (or LookupKey, if that is the superclass), so it comes almost for free by inheriting from Magnitude instead of Object.

Upvotes: 2

Related Questions