Finding asClass usages in Glamour using GTSpotter

In Pharo, String>>asClass is a scripting convenience method that looks up a class based on its name. While in scripts it can be tolerated, using it in production code is an anti-pattern.

Stephane recently pointed out that some classes already exist in Glamour that make use of #asClass. For example:

GLMBrickStructureTrait>>openInBrickWindowLabeled: aLabel
  #GLMSystemWindowBrick asClassIfAbsent: [
    ^ self asMorph openInWindow ].
  ^ #GLMSystemWindowBrick asClass new
    ...
    openCenteredInWorld

This code should clearly not exist, but this is not what this post is about. The question is, how can we quickly find out where is String>>asClass used inside Glamour.

Let’s use Spotter. We start from finding the String>>asClass method.

AsClass.png

We dive in (Cmd+RightArrow):

AsClassSenders.png

We see that there are 10 senders. To find those that are in Glamour, we simply filter by the GLM prefix:

AsClassSendersFiltered.png

Quick and easy.

Posted by Tudor Girba at 11 April 2015, 11:38 pm with tags assessment, spike, story, pharo link
|