Method categories, was: Re: How I wasted one our of my time : -)

Norton, Chris chrisn at Kronos.com
Thu Jun 15 18:31:54 UTC 2000


Hi Stefan, Henrik & friends.

Ever since I started Squeaking, I've been frustrated by its lack of
documentation and categorization of methods -- especially amongst the base
classes.  In fact, I once spent some serious time cleaning up my image
(recategorizing everything), but that image got wiped out.  Sigh.

I still have an algorithm I wrote back in April '99, that does some nifty
auto-categorization stuff.  It doesn't clean up inconsistency problems noted
by Stefan (i.e. printOn: appearing in several different categories), but it
does clean up quite a lot of lazy code.

This algorithm will classify all unclassified instance methods into the
class's parent's instance method categories.

| aClass list |
Smalltalk classNames do: [:each |
	aClass := (Smalltalk at: each).
	aClass superclass notNil
		ifTrue:
			[(aClass organization listAtCategoryNamed:
ClassOrganizer default) do: [:sel |
				list := OrderedCollection new.
				aClass allSuperclasses do: [:cl |
					(cl includesSelector: sel)
						ifTrue:
							[((cl organization
categoryOfElement: sel) ~= ClassOrganizer default)
								ifTrue:
[list addLast: (cl organization categoryOfElement: sel)]].
					(list isEmpty)
						ifFalse: [aClass
organization classify: sel under: list first]]]]]

For example, prior to running this algorithm on my 2.9a image, I see that
EllipseMorph has 5 methods in its "as yet unclassified" category.  After
running the algorithm, I find that all of the instance methods on
EllipseMorph are now classified (way cool!).

Unfortunately, I don't have time today to make this work with class methods
too.  But I thought you might be interested in this stuff anyway!   :-)

Cheers,

---==> Chris





More information about the Squeak-dev mailing list