WEBVTT 00:04.340 --> 00:05.150 Welcome back. 00:05.690 --> 00:09.050 Let's continue working on the hipster's love bookstore code. 00:09.650 --> 00:13.270 This time we're going to refactor the code using a literals. 00:15.180 --> 00:16.450 OK, let's get started. 00:18.320 --> 00:22.320 This is a peer review court that we had been working on in the last lectures. 00:23.030 --> 00:27.200 Let me first comment out the rest of this court temporarily like this. 00:28.080 --> 00:29.400 OK, let's run it now. 00:30.400 --> 00:37.240 Previously, we had added the book titles to the books, one by one, using the index expressions, 00:37.240 --> 00:41.030 right this time, let's use an arrow literal instead. 00:41.470 --> 00:46.180 First, I'm going to change this declaration into a short declaration like this. 00:47.290 --> 00:49.360 This is the beginning of this area, literally. 00:50.050 --> 00:52.600 Remember, it starts with the type, right? 00:52.960 --> 00:56.590 So this is its type, an area of force, string values. 00:56.950 --> 01:02.650 OK, now I'm going to type the opening and closing curly braces for its elementalist like this. 01:03.470 --> 01:06.670 Remember, you're the constant is equal to four. 01:06.910 --> 01:13.240 So right now, this area literally creates an area with four elements limn also temporarily comment 01:13.450 --> 01:14.440 these assignments. 01:14.710 --> 01:16.870 You'll see why I'm doing this in a second. 01:18.030 --> 01:19.740 What the books are, it looks like now. 01:20.090 --> 01:23.030 Can you guess, please post a video and think about it? 01:23.460 --> 01:25.010 I'm here waiting for you. 01:34.300 --> 01:35.490 All right, let's see. 01:35.930 --> 01:40.860 As you can see, this area literally has created a new area with four elements. 01:40.870 --> 01:44.150 All the elements have their zero values now, right? 01:44.470 --> 01:52.280 Remember, Go assigns zero values to an initialized array elements depending on the Herries element 01:52.280 --> 01:52.570 type. 01:52.620 --> 01:52.930 OK. 01:53.940 --> 01:59.190 By the way, this syntax is completely equal to this declaration, syntax double. 02:01.060 --> 02:01.530 On this. 02:02.520 --> 02:07.330 As you can see, it prints the same value, right, because they are the same. 02:07.770 --> 02:14.880 So if you don't have the elements, always use this empty array declaration syntax do not use this short 02:14.880 --> 02:16.170 declarations syntax here. 02:16.650 --> 02:17.220 All right. 02:17.250 --> 02:21.530 Since we know the elements, I'm going to use this array literal syntax instead. 02:21.750 --> 02:24.570 First, let also on command these assignments. 02:25.500 --> 02:28.830 OK, now let's initialize this array with the book titles. 02:28.860 --> 02:36.480 OK, now I'm going to select all the index expressions here by pressing command and keys together enough 02:36.480 --> 02:37.530 times like this. 02:38.480 --> 02:45.260 And I'm going to remove these assignments, OK, now I'm going to move all these literals into the element 02:45.260 --> 02:47.090 list off the books like this. 02:48.030 --> 02:53.880 And lastly, I'm going to type comments for every one of them to separate them from each other like 02:53.880 --> 02:54.210 this. 02:54.630 --> 02:57.990 OK, let me say it, however, now there is an error. 02:58.230 --> 02:58.770 Let's see. 02:59.250 --> 03:00.500 The problem is this. 03:01.200 --> 03:07.230 So for this last element, I need to type it manually because the error hasn't been defined yet. 03:07.830 --> 03:12.030 So I'm going to type Kavkaz revanche manually instead like this. 03:13.140 --> 03:13.920 OK, ready? 03:13.980 --> 03:14.630 Let's run it. 03:15.420 --> 03:18.070 As you can see, the output is the same as before. 03:18.140 --> 03:19.380 Right, cool. 03:20.290 --> 03:24.520 As an example, let's Ormet the last element here like this. 03:24.760 --> 03:25.800 OK, let's try it. 03:26.530 --> 03:29.450 As you can see now, the last element is an attempt string. 03:29.590 --> 03:35.320 Gore has assigned zero value to it automatically because the length of this error is four. 03:36.070 --> 03:40.750 OK, now let's assigned to the last value using an index expression again. 03:44.600 --> 03:50.450 OK, that's right, now the last element is initialized to Kavkaz Revanche, Second Edition. 03:51.350 --> 03:57.260 So as you can see, you can mix an array literal initialization with an index expression assignment, 03:57.590 --> 04:03.000 OK, since we know about all the elements, let's use an ellipsis operator here. 04:03.050 --> 04:08.150 OK, now I'm going to change the year constant here to ellipses like this three. 04:08.150 --> 04:09.330 That's OK. 04:09.860 --> 04:11.330 There is a compiler error. 04:11.360 --> 04:12.620 Now let's check it out. 04:13.460 --> 04:18.080 Go says that this, given an index three is beyond these arrays length. 04:18.980 --> 04:20.270 Let's check it out its length. 04:21.520 --> 04:29.200 As you can see, it's land is three, not four, because the ellipsis sets the area is flanked by looking 04:29.200 --> 04:31.540 at the length of the given elements. 04:31.840 --> 04:34.780 OK, here there are only three elements. 04:35.030 --> 04:37.990 So this area is length automatically becomes three. 04:39.330 --> 04:41.730 So let's remove this index expression here. 04:43.640 --> 04:47.500 Let's move this string literal into the elementalist like this. 04:48.780 --> 04:55.500 Now, let's check out the land again now it's land is far right because there are four elements in the 04:55.600 --> 04:56.130 elementalist. 04:56.130 --> 05:01.620 Now, as the last example, let me show you why this training Comac can be used for. 05:02.760 --> 05:09.210 Let's say I want to change the order of the book titles here, I can easily do so like this. 05:10.290 --> 05:12.130 OK, let's take it back now. 05:12.210 --> 05:18.240 Let me remove the last comment like this, let's try to move the last element, for example, here, 05:18.850 --> 05:20.010 OK, let's say it. 05:21.030 --> 05:24.510 Now, Gore says that there is a syntax error here. 05:25.450 --> 05:32.500 This happens because Gore automatically inserts semicolons after statements or literals. 05:32.920 --> 05:37.960 OK, so here Gore puts a semicolon here automatically. 05:38.650 --> 05:41.410 The elementalist definition ends in here. 05:41.650 --> 05:45.910 But Gore expects a comma or an ending curly brace here. 05:46.480 --> 05:50.010 It can find any of them here than this ever happens. 05:50.710 --> 05:53.260 So let's put a comma here now. 05:53.260 --> 05:53.700 It's OK. 05:54.010 --> 05:57.640 This was one of the benefits of using trailing commas. 05:57.800 --> 06:01.260 OK, by the way, I can also type it like this. 06:01.810 --> 06:03.640 This is also a valid syntax. 06:04.770 --> 06:11.430 A coma is only necessary when the last element is next to an ending trolleybus or a coma. 06:11.730 --> 06:12.090 OK. 06:13.130 --> 06:14.390 All right, that's all for now. 06:14.600 --> 06:16.130 Thank you for watching so far. 06:16.160 --> 06:17.310 Thank you for your patience. 06:17.450 --> 06:18.930 See in the next picture, A.