Previous: , Up: Sharing Cuis   [Index]


11.2 Refactoring to Improve Understanding

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.

ch11-01-SendersOfLeft

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.

ch11-02-RenameLeft

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.

ch11-03-RenameInCategory

Figure 11.3: Rename in Category

Of course, when making changes one wants to see that the result is what one expects.

ch11-04-turnLeft

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.

 CuisLogo Rename #right to #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..

ch11-05-noseSenders

Figure 11.5: Senders of nose

Hmmm, perhaps something more specific. How about #noseDirection? How does that look?

ch11-06-noseDirection

Figure 11.6: Rename nose to noseDirection

 note World menu → Help is your friend. The Terse Guide to Cuise gives access to a large sample of code usages. The Class Comment Browser is an alternate way to find interesting class information. There are also more notes on code maganement and how we use GitHub.

 note 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!


Previous: , Up: Sharing Cuis   [Index]