[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how is polymorphism used?
On Thu, 13 Mar 2003, Russ Ross wrote:
> My first guess would be that in most (not all) applications there
> are a few generic utility classes/modules/functions and the rest of
> the code is pretty tied to certain types, even if the language
> doesn't force this. In other words, for most code you could replace
> it with a statically typed language without really changing much.
>
> What does your experience suggest?
This may not be exactly what you're looking for, but I just did a quick
analysis of the base Squeak Smalltalk image, which contains quite a mix of
library code, UI frameworks, development tools, and various applications.
There are 25846 unique method names defined in the image (in 1811
classes). Of these, 20358 have exactly one implementation (about 79%).
A further 4692 (18%) are only moderately polymorphic, having between 2 and
4 implementations. Another 570 (2%) have between 5 and 10
implementations. The remaining 226 messages (< 1%) are extremely
polymorphic, having more than 10 implementations. Of these, 5 have more
than 100 implementations:
721->#initialize
202->#printOn:
199->#new
107->#step
102->#drawOn:
#step and #drawOn: are both part of the Morphic UI framework, and are
evidently implemented by about 1/4 of the 391 subclasses of Morph.
It's interesting to note that the polymorphic messages get sent more
often, however. Of the 3859 (15%) messages that are sent more than 5
times, more than half of them (1973, 51%) have multiple implementations,
and 561 of them (15%) have 5 or more implementations.
Another interesting analysis would be to look at the same numbers after
eliminating messages that are only ever sent to "self" (the Smalltalk
equivalent of "this"), since these are statically bindable.
I'll leave the drawing of conclusions from all of this to others.
Avi