Welcome back.
Let's continue working on the hipster's love bookstore code.
This time we're going to refactor the code using a literals.
OK, let's get started.
This is a peer review court that we had been working on in the last lectures.
Let me first comment out the rest of this court temporarily like this.
OK, let's run it now.
Previously, we had added the book titles to the books, one by one, using the index expressions,
right this time, let's use an arrow literal instead.
First, I'm going to change this declaration into a short declaration like this.
This is the beginning of this area, literally.
Remember, it starts with the type, right?
So this is its type, an area of force, string values.
OK, now I'm going to type the opening and closing curly braces for its elementalist like this.
Remember, you're the constant is equal to four.
So right now, this area literally creates an area with four elements limn also temporarily comment
these assignments.
You'll see why I'm doing this in a second.
What the books are, it looks like now.
Can you guess, please post a video and think about it?
I'm here waiting for you.
All right, let's see.
As you can see, this area literally has created a new area with four elements.
All the elements have their zero values now, right?
Remember, Go assigns zero values to an initialized array elements depending on the Herries element
type.
OK.
By the way, this syntax is completely equal to this declaration, syntax double.
On this.
As you can see, it prints the same value, right, because they are the same.
So if you don't have the elements, always use this empty array declaration syntax do not use this short
declarations syntax here.
All right.
Since we know the elements, I'm going to use this array literal syntax instead.
First, let also on command these assignments.
OK, now let's initialize this array with the book titles.
OK, now I'm going to select all the index expressions here by pressing command and keys together enough
times like this.
And I'm going to remove these assignments, OK, now I'm going to move all these literals into the element
list off the books like this.
And lastly, I'm going to type comments for every one of them to separate them from each other like
this.
OK, let me say it, however, now there is an error.
Let's see.
The problem is this.
So for this last element, I need to type it manually because the error hasn't been defined yet.
So I'm going to type Kavkaz revanche manually instead like this.
OK, ready?
Let's run it.
As you can see, the output is the same as before.
Right, cool.
As an example, let's Ormet the last element here like this.
OK, let's try it.
As you can see now, the last element is an attempt string.
Gore has assigned zero value to it automatically because the length of this error is four.
OK, now let's assigned to the last value using an index expression again.
OK, that's right, now the last element is initialized to Kavkaz Revanche, Second Edition.
So as you can see, you can mix an array literal initialization with an index expression assignment,
OK, since we know about all the elements, let's use an ellipsis operator here.
OK, now I'm going to change the year constant here to ellipses like this three.
That's OK.
There is a compiler error.
Now let's check it out.
Go says that this, given an index three is beyond these arrays length.
Let's check it out its length.
As you can see, it's land is three, not four, because the ellipsis sets the area is flanked by looking
at the length of the given elements.
OK, here there are only three elements.
So this area is length automatically becomes three.
So let's remove this index expression here.
Let's move this string literal into the elementalist like this.
Now, let's check out the land again now it's land is far right because there are four elements in the
elementalist.
Now, as the last example, let me show you why this training Comac can be used for.
Let's say I want to change the order of the book titles here, I can easily do so like this.
OK, let's take it back now.
Let me remove the last comment like this, let's try to move the last element, for example, here,
OK, let's say it.
Now, Gore says that there is a syntax error here.
This happens because Gore automatically inserts semicolons after statements or literals.
OK, so here Gore puts a semicolon here automatically.
The elementalist definition ends in here.
But Gore expects a comma or an ending curly brace here.
It can find any of them here than this ever happens.
So let's put a comma here now.
It's OK.
This was one of the benefits of using trailing commas.
OK, by the way, I can also type it like this.
This is also a valid syntax.
A coma is only necessary when the last element is next to an ending trolleybus or a coma.
OK.
All right, that's all for now.
Thank you for watching so far.
Thank you for your patience.
See in the next picture, A.