WEBVTT 00:01.920 --> 00:06.270 Malcolm, in this coding lecture, I'm going to show you an example program that will show you what 00:06.270 --> 00:08.280 shadowing means and how to prevent it. 00:09.280 --> 00:16.360 By the way, shallowing problem is very famous out at least once every gopher has fallen into its wicked 00:16.420 --> 00:16.930 trap. 00:17.200 --> 00:18.030 Let's check it out. 00:22.120 --> 00:25.180 All right, now let's first declare a variable named an. 00:26.390 --> 00:28.880 I'm intentionally selected of its name as an. 00:30.110 --> 00:33.710 It's because this Assif bloke here also uses the name. 00:35.680 --> 00:37.270 Now, let's print variable. 00:39.430 --> 00:42.250 Princess and is integer. 00:43.690 --> 00:44.680 Spookies. 00:47.350 --> 00:48.430 You've been shut out. 00:54.280 --> 01:01.270 OK, if I run this program now, can you guess what will happen next, please post the video and think 01:01.270 --> 01:01.750 about it. 01:07.450 --> 01:10.900 OK, let me show you let's run it with a number like this, 40. 01:12.000 --> 01:16.620 As you can see, it, first prints the correct calculation, then it prints Euronext. 01:17.840 --> 01:18.470 But why? 01:21.170 --> 01:27.800 A beginner golfer usually thinks that the available here is the one that's been declared inside the 01:27.800 --> 01:30.200 main function main functions at. 01:31.370 --> 01:39.950 However, the reality is different in the US branch, this is a new variable in shadows, the main functions 01:39.950 --> 01:40.720 and variable. 01:41.180 --> 01:42.920 This is why it's called the shadow. 01:43.730 --> 01:45.140 It creates another variable. 01:45.320 --> 01:47.700 It's in an inner scope with the same name. 01:48.500 --> 01:50.410 So there are two and variables. 01:51.020 --> 01:54.020 This can be very confusing and it can lead to bugs. 01:54.990 --> 02:01.350 This is happening because of the declaration here, remember, the declaration can declare new variables 02:01.350 --> 02:04.270 and assigned to the existing variables at the same time. 02:05.190 --> 02:09.620 Since this is a new block, it declares variables instead of changing their value. 02:10.200 --> 02:12.350 Can you see this short declaration, operator? 02:12.930 --> 02:14.240 That is the cause of terror. 02:14.910 --> 02:16.680 So how to prevent this problem? 02:17.310 --> 02:17.940 Let me show you. 02:19.200 --> 02:21.420 Let's declare a new era variable like this. 02:26.230 --> 02:28.610 As you can see, variables type is error. 02:29.020 --> 02:32.850 It's a pretty clear type, like int floor 64. 02:32.890 --> 02:38.410 And so let's change this radicalisation into an assignment statement like this. 02:39.500 --> 02:45.740 As you can see, you can also use an assignment statement here, so instead of using Cullen's equal 02:45.740 --> 02:49.050 operator, I've just used the equal operator. 02:49.220 --> 02:51.100 This is the assignment now. 02:51.110 --> 02:51.710 It's voluntary. 02:51.710 --> 02:53.320 Declare new variables here. 02:54.140 --> 02:59.300 Instead, it will just use the variables that belong to the main function, which I just declare the 02:59.300 --> 02:59.900 ball here. 03:03.420 --> 03:06.900 OK, now this is the result, back again to the unwearable. 03:08.330 --> 03:10.880 So that you can see it in the end when I print it. 03:11.060 --> 03:11.390 OK. 03:15.700 --> 03:16.120 All right. 03:19.360 --> 03:25.150 Now, let's run it again, like this 40 is you can see this time it Prince 80 correctly. 03:25.360 --> 03:27.970 So now there isn't any Qadam issue now. 03:29.990 --> 03:35.900 There is only one viable, not so you can use the embeddable even after the if statement, as you've 03:35.900 --> 03:42.050 seen here and now, since the army belongs to the main function, and if statement is inside of the 03:42.050 --> 03:48.500 main function, both the main function and the if statement can see and changed the same and variable. 03:49.390 --> 03:51.910 That's why it brings 80 instead of zero. 03:53.910 --> 03:59.790 By the way, go and let you know about the Shadmi problem automatically if you configure your escort. 04:00.600 --> 04:01.940 Let me show you how it works. 04:03.400 --> 04:07.510 Go to the View menu here and select this comment, Pelletiere. 04:08.840 --> 04:14.210 Then type settings, then select this one, open settings, Jason. 04:15.140 --> 04:18.230 And here, go to the bottom of this configuration file. 04:19.100 --> 04:21.710 And type this very same configuration options. 04:23.320 --> 04:28.210 If they exist already, just change them with this, then just save the file. 04:32.300 --> 04:38.000 For example, here, it tells me that there is a shadowing problem and it shows me the exact location 04:38.000 --> 04:38.590 of the problem. 04:39.230 --> 04:43.820 So here it tells me that these light shuttles available declared at these light. 04:44.830 --> 04:51.640 So Galvan's me, that's the honorable of the if statement châteaux the main funks and rebel this way 04:51.640 --> 04:54.500 you can catch most of the shallowing errors when they happen. 04:55.090 --> 04:55.650 All right. 04:55.660 --> 04:57.490 I hope now you understand the upshot of. 05:03.080 --> 05:03.790 Congrats. 05:03.830 --> 05:05.760 Now, you know what's a simple statement? 05:05.780 --> 05:11.880 How Scottsburg made it and the famous shot, I mean, gotcha, OK, see in the next picture by.