1 00:00:01,260 --> 00:00:03,390 In this video, I’d like to show you that Pharo 2 00:00:03,557 --> 00:00:06,040 also offers the possiblity to have an assistant that 3 00:00:06,207 --> 00:00:08,640 checks your code quality, it is called either 4 00:00:08,807 --> 00:00:11,450 the Quality Assistant, or Code Critics. It runs 5 00:00:11,617 --> 00:00:14,770 automatically good practice rules on your code. 6 00:00:15,710 --> 00:00:17,040 Let’s have a look at it more closely. 7 00:00:17,300 --> 00:00:19,220 You’ve seen that each time you browse a class, 8 00:00:19,387 --> 00:00:22,770 you have this pop-up that is displayed. 9 00:00:22,937 --> 00:00:25,300 In fact, what happens is that automatically, 10 00:00:25,467 --> 00:00:27,770 while I’m browsing, 11 00:00:27,937 --> 00:00:32,010 (let’s choose CubHelix to see),you have 12 00:00:32,177 --> 00:00:35,740 this little area here where indications 13 00:00:37,020 --> 00:00:40,390 are displayed. And when I go on the package also. 14 00:00:43,110 --> 00:00:46,350 As it is a little bit difficult to find a 15 00:00:46,517 --> 00:00:49,240 convincing example, we will use our own code and 16 00:00:49,407 --> 00:00:52,090 write ugly code in it, this way you will see. 17 00:00:52,280 --> 00:00:57,080 If I go into Counter, let’s imagine for example that 18 00:00:57,247 --> 00:01:00,480 I leave debugging code, 19 00:01:02,350 --> 00:01:04,730 here the system tells me automatically 2 things. 20 00:01:05,180 --> 00:01:09,310 It says that there is debugging code left 21 00:01:09,477 --> 00:01:12,200 in the method. What can I do ? 22 00:01:12,940 --> 00:01:14,540 I can understand where does this rule come from. 23 00:01:14,707 --> 00:01:16,680 So I click on it, it tells me to use 24 00:01:16,847 --> 00:01:19,800 breakpoints, which is not specially smart in production code. 25 00:01:21,280 --> 00:01:25,260 It can tell me, I will automatically solve this problem. 26 00:01:25,427 --> 00:01:26,340 Let’s try, we will see. 27 00:01:27,300 --> 00:01:28,530 It says to suppress this. 28 00:01:28,720 --> 00:01:30,240 Ok, very good. 29 00:01:30,950 --> 00:01:32,710 And as a consequence, I don’t have this problem anymore. 30 00:01:34,540 --> 00:01:36,700 You’ve seen that we do it while I am 31 00:01:36,867 --> 00:01:40,100 programming. Finally, the system will react. 32 00:01:40,460 --> 00:01:43,350 Now, there is another way to do it, I can 33 00:01:43,517 --> 00:01:48,250 open the Critic browser on my package. 34 00:01:48,417 --> 00:01:49,460 here it is a very small package. 35 00:01:50,960 --> 00:01:55,460 Let’s make a mistake in order to see it. 36 00:01:55,627 --> 00:01:56,440 Here if I do "self halt" 37 00:02:01,020 --> 00:02:02,790 or far example I do another method, 38 00:02:03,460 --> 00:02:06,910 I create an “increment3” method and 39 00:02:07,077 --> 00:02:08,790 I invoke a method which doesn’t exist. 40 00:02:08,957 --> 00:02:11,740 Let’s call it "foofoo". 41 00:02:13,110 --> 00:02:16,010 So here it is red but let’s suppose I haven’t 42 00:02:16,177 --> 00:02:18,900 noticed it because of a feverishness state… 43 00:02:20,590 --> 00:02:24,360 I’m gonna use the Critic browser 44 00:02:27,380 --> 00:02:31,250 on my code and here the Critic browser 45 00:02:31,417 --> 00:02:32,770 shows me the set of rules. 46 00:02:33,720 --> 00:02:38,620 There is in fact quite a lot rules 47 00:02:38,787 --> 00:02:42,790 with explanations. If you have this code there, in this 48 00:02:42,957 --> 00:02:46,200 case you’d better use it that way, if there is 49 00:02:46,367 --> 00:02:47,450 an allocation inside. 50 00:02:47,617 --> 00:02:49,620 There are several kinds of rules. 51 00:02:50,040 --> 00:02:52,160 There are rules linked to optimisation, rules 52 00:02:52,327 --> 00:02:54,300 that can potentially identify fixed bugs. 53 00:02:54,650 --> 00:02:56,600 Rules that identify true. 54 00:02:56,860 --> 00:02:59,200 If I go there, I see the code. 55 00:02:59,367 --> 00:03:03,050 I can browse the definition as we did before, 56 00:03:03,217 --> 00:03:05,810 or I can transform it. 57 00:03:08,180 --> 00:03:12,160 And the warning disappeared. 58 00:03:13,610 --> 00:03:15,400 Now it is important to notice that 59 00:03:15,567 --> 00:03:17,920 all these rules are based on heuristics. 60 00:03:18,087 --> 00:03:19,700 This means that sometimes you do things 61 00:03:19,867 --> 00:03:22,840 that are not very good. You know it and you 62 00:03:23,007 --> 00:03:24,200 have to let it that way in the system. 63 00:03:24,367 --> 00:03:28,840 You can also say that this is a false 64 00:03:29,007 --> 00:03:33,660 positive. Let’s imagine I have a “foofoo” 65 00:03:33,827 --> 00:03:36,660 message and I know I want to keep it, I can 66 00:03:36,827 --> 00:03:40,240 specify that this rule is false for this method. 67 00:03:41,850 --> 00:03:44,850 I will write it. 68 00:03:45,017 --> 00:03:46,510 Here it is in grey, what does it mean? 69 00:03:46,677 --> 00:03:49,690 It means that later I could look at it 70 00:03:49,857 --> 00:03:51,310 and say myself maybe this rule was true and 71 00:03:51,477 --> 00:03:53,490 it made sense to take another 72 00:03:57,250 --> 00:03:57,883 look at it. 73 00:03:58,410 --> 00:04:00,640 We can save the critics. 74 00:04:00,807 --> 00:04:04,910 It means we save the rules results and 75 00:04:05,077 --> 00:04:06,670 as well the false positives. 76 00:04:07,290 --> 00:04:08,850 When we write something was false, we don’t want 77 00:04:09,017 --> 00:04:11,000 the system to repeat it constanltly 78 00:04:11,167 --> 00:04:12,680 each time we run the rules. 79 00:04:13,400 --> 00:04:18,230 So when I save the critics, it will put them in a manifest. 80 00:04:18,470 --> 00:04:21,690 Let’s look at it. Here there is my manifest which will 81 00:04:21,857 --> 00:04:23,920 be assigned a version associated with the system. 82 00:04:24,087 --> 00:04:26,410 You don’t need to see how it is coded inside, we don’t care. 83 00:04:26,577 --> 00:04:29,400 The Manifest enables to code things,but no matter. 84 00:04:29,700 --> 00:04:32,590 You don’t touch to this, this is the code-critics that will use it 85 00:04:32,757 --> 00:04:34,120 for the next executions. 86 00:04:34,287 --> 00:04:36,260 And you have a manifest for each package. 87 00:04:36,700 --> 00:04:38,100 When you assign a version to the code, you 88 00:04:38,267 --> 00:04:39,920 also assign a version to your manifests, and when you 89 00:04:40,087 --> 00:04:42,880 run again your code-critics, automatically it 90 00:04:43,047 --> 00:04:44,890 will take into account all the false positives and all 91 00:04:45,057 --> 00:04:47,040 the meta-remarks you put in it. 92 00:04:47,207 --> 00:04:49,510 So what is really interesting with those quality 93 00:04:49,677 --> 00:04:53,390 rules is that Pharo integrates them in a development process. 94 00:04:53,557 --> 00:04:56,010 We will make sure that, 95 00:04:56,177 --> 00:04:58,570 each time you commit your project, there are 96 00:04:58,737 --> 00:05:01,170 Jenkins servers that will load and run 97 00:05:01,337 --> 00:05:04,000 automatically those quality rules to check that 98 00:05:04,167 --> 00:05:05,920 your program really follows those rules.