As I was browsing a couple of packages a couple of days ago, I noticed something funny. Nearly all of the classes seemed to begin with the letter S. Me, a real fan of using namespaces to create little "microverses" where you're free to express class names without worrying about semantic clash, and nearly all of my classes start with the same letter. This of course, degenerates searching for a class in an "alphabetical" list to a linear method. So I wrote a little script.
This is blogged in the same vein as Vassili's Just Browsing entry: interesting ways to programatically access your program space.
I used a workspace and concocted the following block (why a block? see here. I've been accused of too freely extending base classes, but I draw the line at printMostPopularLetterWithPercentageToTheTranscript):
showMostPopular := [:pkg | | classes grouped mostPopular | classes := pkg definedClasses. grouped := classes groupedBy: [:eachClass | eachClass name first]. mostPopular := (grouped associations asSortedCollection: [:a :b | a value size < b value size]) last. Transcript show: ('<1p> <2p>% <3s>' expandMacrosWith: pkg with: mostPopular value size / classes size * 100.0 with: (String with: mostPopular key)); cr].
Then you can use something like:
showMostPopular value: (Store.Registry packageNamed: 'YourPackageOfInterest'
(Store.Registry allPackages asSortedCollection: [:a :b | a name < b name]) do: [:eachPkg | eachPkg definedClasses size > 10 ifTrue: [showMostPopular value: eachPkg]]
This second one is fun, because it shows the results for all comparable sized packages in the system. I was kind of amused. There's some obvious ones like WinLooks which of course is going to have 100% W.