views:

89

answers:

3

There are two main reasons for calling "self class": Either for doing user-space things such as invoking static methods, creating new objects or obtaining constants. Or for reflecting on one's self. I'd be curios to know how often each of them occurs.

What's the best way to query the currently loaded Pharo code base? Are there built-in tools, or should I use SOUL?

+1  A: 

The built-in tools that will help you to introspect any class/object in the system are: The System Browser, The Inspector and The Object Explorer. See the chapter "Developing in Squeak" in Squeak by Example. The information you find there is relevant to Pharo.

Vijay Mathew
+2  A: 

Opening up a Browser, going to Object, selecting #class and hitting "senders" will show you all the senders of #class. That's not great for answering "how often each of them occurs" though.

The way to get the same call sites in a more manipulable form is with Object allCallsOn: #class which gives a collection of senders. Perhaps run some #select: calls to find out some numbers?

Or use the Refactoring Browser: it has things like FinderTool to search based on AST structure.

Edit: As mathk points out, sometimes senders-of won't work, because of special messages or inlined messages. There's an interesting discussion on the vm-dev list on the topic.

Frank Shearar
Be careful that #class might be a special bytecode. So you may not find sender with the button "senders", Because no more #class literal is left in the CompiledMethod. I can't remember if it's the case but the same apply for inline send (#ifTrue:#ifFalse:, #and:, ...)
mathk
That's a good point, mathk. Look at Object>>future in Squeak Trunk for another example. That's not inlined, but transformed at compile time (into #futureDo:at:args or #futureSend:args:. Also look at Mariano Martinez Peck's recent explorations on vm-dev, for Squeak/Pharo's VM and special sends.
Frank Shearar
+1  A: 

There is no such thing as static method in smalltalk. If you did not understand that you did not understand what class is.

mathk