Browsing through the code, I note a method named #left, which seems perhaps
like an abbreviation. I can ask for senders to see how #left is used
in code elsewhere.
Figure 11.1: Senders of left
I notice that most uses of #left are to indicate a position,
not take an action. How can I fix that?
Because people frequently want to change things for the better, there are a number of handy tools to help do this.
Now I could look at our uses of #left in Spacewars!, but the Cuis IDE
already knows how to do this!
If I right-click on the Method Pane in the Browser, I get a context menu with selections to help me out. Here I choose Rename.
Figure 11.2: Rename left
Now the tools that help us refactor code are quite powerful, so
restraint is called for. I don’t want to change all uses of
#left in the Cuis-Smalltalk system, just in the Spacewar!
category.
Figure 11.3: Rename in Category
Of course, when making changes one wants to see that the result is what one expects.
Figure 11.4: Results of Renaming
As I am not perfect, I tend to save the Cuis-Smalltalk image before I make large changes using powerful tools. If something happens that I did not want, I can then quit the image without saving and restart the saved image which remembers the world before I made the change.
Rename
#rightto#turnRight.
Exercise 11.1: Renaming a method
Looking around some more in the Browser, I notice the method
SpaceShip>>nose.
Where did I use this? Ah, senders..
Figure 11.5: Senders of nose
Hmmm, perhaps something more specific. How about #noseDirection?
How does that look?
Figure 11.6: Rename nose to noseDirection
World menu →
Helpis your friend. TheTerse Guide to Cuisegives access to a large sample of code usages. TheClass Comment Browseris an alternate way to find interesting class information. There are also more notes on code maganement and how we use GitHub.
We want to share with you! Please visit packages at the main Cuis-Smalltalk repository at https://github.com/Cuis-Smalltalk, search GitHub for repositories with names starting with Cuis-Smalltalk-, and perhaps take a look at tutorials and information in https://github.com/Cuis-Smalltalk/Learning-Cuis.
There is much more to explore, but this book is an introduction and we have to stop writing text somewhere. This is a good place. We want to get back to writing code! And we look forward to seeing your projects!
Welcome to Cuis-Smalltalk!