1 00:00:01,250 --> 00:00:03,460 In this video, I’d like to show you that Nautilus 2 00:00:03,870 --> 00:00:06,710 offers refactoring. What is refactoring? 3 00:00:07,050 --> 00:00:11,560 It’s an operation that transforms code while 4 00:00:11,727 --> 00:00:13,000 preserving its behaviour. 5 00:00:13,320 --> 00:00:15,850 You have to note that historically refactoring has been 6 00:00:16,017 --> 00:00:18,700 been implemented for the first time in Pharo’s ancestor, 7 00:00:18,867 --> 00:00:21,840 and after that in all the languages like Java. 8 00:00:22,170 --> 00:00:26,470 As soon as 95, Smalltalk had a refactoring tool 9 00:00:26,637 --> 00:00:27,890 and Pharo’s one is inspired by this tool. 10 00:00:28,540 --> 00:00:31,070 So let’s open Nautilus to look at the types 11 00:00:31,237 --> 00:00:32,020 of refactoring proposed. 12 00:00:33,320 --> 00:00:36,440 We will work on our class. 13 00:00:38,000 --> 00:00:39,800 Refactoring is at several levels. 14 00:00:39,967 --> 00:00:41,790 There is refactoring at the class level, at the 15 00:00:41,957 --> 00:00:45,330 method level and at the code level, we’ve got 16 00:00:48,710 --> 00:00:49,343 all those types of refactoring. 17 00:00:51,270 --> 00:00:53,120 You can have refactoring at the instance 18 00:00:53,287 --> 00:00:56,020 variables level and at the class variables level. 19 00:00:57,550 --> 00:01:00,580 When a refactoring is very useful it appears 20 00:01:01,490 --> 00:01:05,320 at the highest level in the menus, for you to 21 00:01:05,487 --> 00:01:07,490 go faster, you don’t need to click on class, 22 00:01:07,960 --> 00:01:09,210 refactoring, Rename, it is here. 23 00:01:10,140 --> 00:01:14,690 In the same way, for methods 24 00:01:14,857 --> 00:01:17,310 refactoring, you will have all those methods there, 25 00:01:19,850 --> 00:01:22,470 with also Rename, as it is an important refactoring 26 00:01:22,637 --> 00:01:25,310 at this level. Now if I choose another 27 00:01:25,477 --> 00:01:28,750 piece of code, they are not very complicated 28 00:01:28,917 --> 00:01:33,820 in this class, we will have the following refactorings 29 00:01:35,350 --> 00:01:38,040 working at the method code level. 30 00:01:41,300 --> 00:01:45,450 If I rename, if I do Rename on the Counter class, 31 00:01:45,617 --> 00:01:50,020 I call it Counter Class2, the system says ok. 32 00:01:50,187 --> 00:01:51,300 I do a Rename, all right. 33 00:01:55,130 --> 00:01:56,710 It gives me feedback, I don’t know exactly what this means 34 00:01:56,877 --> 00:01:57,960 but no matter, I ignore it. 35 00:01:58,870 --> 00:02:00,750 And here, I see that where the Counter 36 00:02:04,510 --> 00:02:08,710 Class was invoked it is now Counter 2 instead. 37 00:02:10,000 --> 00:02:14,780 This is typically a class rename 38 00:02:14,947 --> 00:02:15,580 refactoring. 39 00:02:16,490 --> 00:02:18,830 SO now, if I want to rename, and this is a very 40 00:02:19,000 --> 00:02:23,480 good example, let’s imagine I want to rename the increment method. 41 00:02:24,450 --> 00:02:27,230 I do Rename, and as I lack inspiration, 42 00:02:27,397 --> 00:02:28,520 I will call it Increment2. 43 00:02:31,480 --> 00:02:33,670 Here the system tells me: “Be careful” 44 00:02:33,837 --> 00:02:35,550 So I am careful. 45 00:02:36,350 --> 00:02:40,520 “Be careful, you are about to rename 46 00:02:41,740 --> 00:02:44,630 several (there are around 10 implementors in the 47 00:02:44,797 --> 00:02:48,750 system), you are about to rename them, do you really want to do this? 48 00:02:48,917 --> 00:02:50,600 First, I don’t want to do it, second I don’t 49 00:02:50,767 --> 00:02:52,730 want neither to select or unselect. 50 00:02:53,470 --> 00:02:56,580 So we could do it, it enables to show that, 51 00:02:56,747 --> 00:02:58,700 at the end, the programmer is still in charge to 52 00:02:58,867 --> 00:03:00,490 choose. I don’t want to do it. 53 00:03:01,000 --> 00:03:03,700 However what I can do is saying: 54 00:03:03,867 --> 00:03:06,630 “I am only working on MyCounter package 55 00:03:06,797 --> 00:03:09,450 and I don’t really the rest of the system 56 00:03:09,617 --> 00:03:11,020 to be modify automatically. 57 00:03:11,310 --> 00:03:13,680 So I say to Nautilus: “I’d like you 58 00:03:13,847 --> 00:03:17,280 to open a browser on my package only and 59 00:03:17,447 --> 00:03:20,380 that all the operations refer to that selection. 60 00:03:20,890 --> 00:03:23,770 That’s what I do with browse scoped. 61 00:03:26,530 --> 00:03:28,710 That what you can also get by pressing 62 00:03:28,877 --> 00:03:30,180 the Scoped button, that’s the same thing. 63 00:03:30,570 --> 00:03:32,940 That’s a feature so interesting that it has a 64 00:03:33,107 --> 00:03:36,240 button. The difference between those 2 worlds, 65 00:03:36,407 --> 00:03:40,780 if you look at them, is that here I have all my packages 66 00:03:40,947 --> 00:03:41,890 and here I only have one package. 67 00:03:42,057 --> 00:03:45,310 I could have several, I only have one selection of these packages. 68 00:03:45,477 --> 00:03:47,120 And now, if I want to modify increment 69 00:03:47,287 --> 00:03:52,200 I can say: “Rename” 70 00:03:52,460 --> 00:03:57,180 as increment2 and it will do it only 71 00:03:57,500 --> 00:04:01,510 locally on the package or on the selection in the scoped browser. 72 00:04:03,380 --> 00:04:05,590 I click on OK, and now we will look at the tests. 73 00:04:05,757 --> 00:04:08,150 My tests still work, they are all green. 74 00:04:08,480 --> 00:04:11,890 And I see that now all my 75 00:04:12,057 --> 00:04:13,790 Increment have been renamed as Increment2. 76 00:04:16,800 --> 00:04:18,890 In this video we have seen that Pharo 77 00:04:19,057 --> 00:04:21,610 offers you a variety of operations, 78 00:04:21,777 --> 00:04:25,080 selections and code manipulations, with extra 79 00:04:25,247 --> 00:04:27,960 restrictions on packages subsets 80 00:04:28,200 --> 00:04:30,630 to control where changes will be applied. 81 00:04:31,110 --> 00:04:32,870 In Pharo, you also have 82 00:04:33,037 --> 00:04:35,240 a tool that will enable to rewrite code 83 00:04:35,407 --> 00:04:38,060 automatically, I won’t expand on it, I you really need it 84 00:04:38,227 --> 00:04:40,650 you have to ask for it, there is a specific 85 00:04:40,817 --> 00:04:42,310 tool to do this kind of actions. 86 00:04:43,160 --> 00:04:45,480 Now the last point I wanted to show you 87 00:04:45,647 --> 00:04:50,410 is that often you have operations that are 88 00:04:50,577 --> 00:04:51,210 proposed, generated. 89 00:04:51,470 --> 00:04:54,900 You will apply them, the system will propose to execute them 90 00:04:55,067 --> 00:04:57,330 but it is not sure it will work, it will be really appropriate. 91 00:04:57,890 --> 00:05:00,810 What Pharo proposes is the same as what Nautilus proposes, 92 00:05:01,000 --> 00:05:03,460 it is what we call smart suggestions. 93 00:05:03,627 --> 00:05:08,090 Smart suggestions are a tool which knows 94 00:05:08,520 --> 00:05:12,530 and propose you operations based on the current selection. 95 00:05:14,120 --> 00:05:18,590 For example, here it can propose me to do 96 00:05:18,757 --> 00:05:22,510 Extract method. It is not very interesting in this 97 00:05:22,677 --> 00:05:25,900 case, or an Inline method. But it means that if I 98 00:05:26,067 --> 00:05:29,230 selection for example the allocation, I won’t have at all 99 00:05:29,397 --> 00:05:32,490 the same operations available. 100 00:05:33,400 --> 00:05:36,110 If I am on a class, it will ask me to 101 00:05:36,277 --> 00:05:37,710 browse the references, to rename the class. 102 00:05:37,877 --> 00:05:41,000 And you see that depending on where the cursor is 103 00:05:41,710 --> 00:05:43,000 I don’t have the same operations.