In this video, I’d like to show you that Nautilus
offers refactoring. What is refactoring?
It’s an operation that transforms code while
preserving its behaviour.
You have to note that historically refactoring has been
been implemented for the first time in Pharo’s ancestor,
and after that in all the languages like Java.
As soon as 95, Smalltalk had a refactoring tool
and Pharo’s one is inspired by this tool.
So let’s open Nautilus to look at the types
of refactoring proposed.
We will work on our class.
Refactoring is at several levels.
There is refactoring at the class level, at the
method level and at the code level, we’ve got
all those types of refactoring.
You can have refactoring at the instance
variables level and at the class variables level.
When a refactoring is very useful it appears
at the highest level in the menus, for you to
go faster, you don’t need to click on class,
refactoring, Rename, it is here.
In the same way, for methods
refactoring, you will have all those methods there,
with also Rename, as it is an important refactoring
at this level. Now if I choose another
piece of code, they are not very complicated
in this class, we will have the following refactorings
working at the method code level.
If I rename, if I do Rename on the Counter class,
I call it Counter Class2, the system says ok.
I do a Rename, all right.
It gives me feedback, I don’t know exactly what this means
but no matter, I ignore it.
And here, I see that where the Counter
Class was invoked it is now Counter 2 instead.
This is typically a class rename
refactoring.
SO now, if I want to rename, and this is a very
good example, let’s imagine I want to rename the increment method.
I do Rename, and as I lack inspiration,
I will call it Increment2.
Here the system tells me: “Be careful”
So I am careful.
“Be careful, you are about to rename
several (there are around 10 implementors in the
system), you are about to rename them, do you really want to do this?
First, I don’t want to do it, second I don’t
want neither to select or unselect.
So we could do it, it enables to show that,
at the end, the programmer is still in charge to
choose. I don’t want to do it.
However what I can do is saying:
“I am only working on MyCounter package
and I don’t really the rest of the system
to be modify automatically.
So I say to Nautilus: “I’d like you
to open a browser on my package only and
that all the operations refer to that selection.
That’s what I do with browse scoped.
That what you can also get by pressing
the Scoped button, that’s the same thing.
That’s a feature so interesting that it has a
button. The difference between those 2 worlds,
if you look at them, is that here I have all my packages
and here I only have one package.
I could have several, I only have one selection of these packages.
And now, if I want to modify increment
I can say: “Rename”
as increment2 and it will do it only
locally on the package or on the selection in the scoped browser.
I click on OK, and now we will look at the tests.
My tests still work, they are all green.
And I see that now all my
Increment have been renamed as Increment2.
In this video we have seen that Pharo
offers you a variety of operations,
selections and code manipulations, with extra
restrictions on packages subsets
to control where changes will be applied.
In Pharo, you also have
a tool that will enable to rewrite code
automatically, I won’t expand on it, I you really need it
you have to ask for it, there is a specific
tool to do this kind of actions.
Now the last point I wanted to show you
is that often you have operations that are
proposed, generated.
You will apply them, the system will propose to execute them
but it is not sure it will work, it will be really appropriate.
What Pharo proposes is the same as what Nautilus proposes,
it is what we call smart suggestions.
Smart suggestions are a tool which knows
and propose you operations based on the current selection.
For example, here it can propose me to do
Extract method. It is not very interesting in this
case, or an Inline method. But it means that if I
selection for example the allocation, I won’t have at all
the same operations available.
If I am on a class, it will ask me to
browse the references, to rename the class.
And you see that depending on where the cursor is
I don’t have the same operations.