84% of all instance-methods are unary !

Torge Husfeldt torge.husfeldt at gmx.de
Fri Jun 13 08:57:49 UTC 2003


Hi again!

I think your code below is wrong!
First of all: how many wheels are you trying to reinvent?
Please look at String>>numArgs and the Class Bag.
Second: since you're using one-based arrays your unary selectors (selectors
with no argument) are assigned the position _one_. So are binary keyword 
selectors.
Third: why are you limiting the range of argument counts beforehand? If you 
were only interested
in the finding you promoted in the subject a two elemented array would have 
sufficed.
So here's the correct code and the answers my (not so virgin) image geve 
me.

result _ Bag new.
Class allSubInstances do:[:aClass |
	aClass selectors do:[:sel |
		result add: sel numArgs]].
{result sortedCounts. result cumulativeCounts}
 #(a SortedCollection(13905->0 9594->1 2682->2 802->3 382->4 202->5 71->6 
29->7 14->8 5->9 3->10 1->11 1->12 1->13 1->14) #(50.2->0 84.9->1 94.5->2 
97.4->3 98.8->4 99.5->5 99.8->6 99.9->7 100.0->8 100.0->9 100.0->10 100.0- 
>11 100.0->12 100.0->13 100.0->14))

That means a mere 50% for the unary selectors. May be quite a 
disappointment compared to your numbers.

Cheers,
Torge

P.S.: I didn't mean to sound so rude; it just came out that way. Hey code 
on! Just remember to look for some conveiniences the system offers you now 
and then.

On Tue, 10 Jun 2003 18:29:00 +0200, Markus Gaelli <gaelli at emergent.de> 
wrote:

> Hi,
>
> If my code below is right, around _84 %_ (!) of all instance-methods
> in Squeak 3.6-5247 are unary, thus easy executable, if there were 
> examples
> for their objects.
> Think of the coverage we could gain, if we had more examples.
> Put in assertions in your code, and we have lots of real failure checking
> tests too.
>
> Markus
>
> ----------
>
> |aMethodSigBlock  anArray maxParameters|
> maxParameters:=20.
> aMethodSigBlock :=
> 	[:aClass || myArray |
> 	myArray _ Array new: maxParameters withAll: 0.
> 	aClass selectors
> 		do: [:aSel |
> 			aSel isUnary
> 				ifTrue: [myArray at: 1 put: (myArray at: 1) + 1].
> 			aSel isInfix
> 				ifTrue: [myArray at: 2 put: (myArray at: 2) + 1].
> 			aSel isKeyword
> 				ifTrue: [| anIndex |
> 					anIndex _ (aSel findTokens: ':') size.
> 					myArray at: anIndex put: (myArray at: anIndex) + 1]].
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
here you could have solved the problem by usin anIndex+1 (please rename 
that numArgs + 1) as in:
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 					myArray at: numArgs + 1 put: (myArray at: numArgs +1) + 1]].

> 		myArray].
>
> anArray := Array new: maxParameters withAll: 0.
> Object withAllSubclasses do: [:e | e isMeta ifFalse: [anArray := anArray 
> + (aMethodSigBlock value: e)]].
> anArray,{(anArray first / anArray sum) asFloat}
>
> #(22787 2854 796 381 202 71 28 13 5 3 1 1 0 1 0 0 0 0 0 0 
> 0.839516634122978)
>
>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/



More information about the Squeak-dev mailing list