50% of all instance-methods are unary ! was: 84% of all instance-methods are unary !

Stephane Ducasse ducasse at iam.unibe.ch
Fri Jun 13 11:43:09 UTC 2003


Markus

even if you find unary messages this does not mean that we will have an  
easy test coverage.
For example
	Browser open

is unary but try to come up with a test for the browser

Stef

On Friday, June 13, 2003, at 12:19 PM, Markus Gaelli wrote:

> Hi again,
>
> having thought about my mistakes a bit,
> I think, they arouse because I was to blind
> to use String >> numArgs, as they where not defined in
> Symbol but its superclass, where I
> didn't look for them.
>
> I saw "isUnary" and "isInfix" or "isKeyword" in Symbol,
> and so I was somehow convinced, that all
> "Symbol plays the role of a selector"-methods
> are found there. And I didn't see a numArgs-method.
> (Next time I won't browse code, but use the
> method-finder...)
>
> Maybe we should move them also to String,
> so that the role of Symbol/String as selector
> is stored in only one place?
> I will add that to the KCP-Swiki.
>
> Markus
>
>> Hi Torge,
>>
>> I certainly agree with all your corrections.,
>> thanks for posting them.
>> Where was my mind, when I coded that,
>> I think I do better on the average...
>>
>> 84% seemed really high.
>>
>> Markus
>>
>>> 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:
>>> vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 
>>> vvvvvvvvvvvvvv
>>> 					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