Keri: to excavate, reveal or extract (buried remains)
Another interesting application of Spy, is to extract type information from unit test execution. Exemplified on Mondrian:
TypingPackageSpy runTestAndViewTypesForPackageNamed: ’Mondrian’
This generate the following picture (its size is 16983x705 pixels, click on it to zoom in):
The visualization is specified as:
- Encapsulating squares are classes
- Inheritance between classes is indicated with edges. A superclass is located above its subclasses. A tree layout is used to order classes.
- Inner squares are methods. The height of a method is the number of different classes the argument of the methods take. The width the number of different classes the return value takes. When a method is colored in pink, then the type Object is the most specialized common type for the return value. When a method is colored in red, it hasn’t been covered by the program execution.
How the visualization help improving a program?
Two different kind of actions have to be taken once a visualization has been computed:
- If the visualization has been produced from running unit tests, then methods in red ought to be covered by additional tests
- You should then draw your attention to pink methods. A large method says that the set of types its arguments and/or return value may take is large. The pink color says that Object is the only common type that can be determined for the return value. As a programmer, you should inspect pink methods and decide whether according the semantics you wished to give to the method Object is really expected. Classical symptoms for this situation is when nil values are returned or when your class hierarchy is illy defined.
It could be that you wish to particularize the visualization. This happens when Object is too generic for you (i.e., you are interested in identifying too generic type, but still being a subclass of Object). The class KeriTypeFeedback is the entry point of the profiler. It contains a method called viewSoftwareAnomalies that can be easily customized.
How to contact the author?
Feedback are very much appreciate (interesting for a type feedback mechanism isn’t it ? :-) Drop few lines to the email that can be found on http://bergel.eu