Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,580 --> 00:00:05,440
There's one last little item I want to point out about our current deck implementation, if we scroll
2
00:00:05,440 --> 00:00:10,210
down to the deck constructor, so here it is right here and find our double nested for loop.
3
00:00:10,240 --> 00:00:11,080
Here it is right here.
4
00:00:11,440 --> 00:00:12,920
We'll find the card constructor.
5
00:00:13,390 --> 00:00:17,500
At present, we are passing in the rank as the first argument and the suit as the second.
6
00:00:18,100 --> 00:00:23,890
Now, I want to show you a very easy way that we could introduce a kind of nasty bug to our program
7
00:00:24,680 --> 00:00:29,060
if I were to swap the order in which I pass in the rank in the suit.
8
00:00:29,530 --> 00:00:30,940
So now it's suit and rank.
9
00:00:31,360 --> 00:00:35,160
I get absolutely no feedback telling me that I just made an error.
10
00:00:35,680 --> 00:00:38,350
In fact, I can still run the program successfully.
11
00:00:39,600 --> 00:00:41,800
But now I get some very weird output.
12
00:00:41,850 --> 00:00:45,790
I see diamonds of diamonds of two and diamonds at three and so on.
13
00:00:46,350 --> 00:00:48,330
So this is definitely a nasty little bug.
14
00:00:48,330 --> 00:00:52,490
And I get no feedback from Darte telling me that there's any issue here whatsoever.
15
00:00:53,340 --> 00:01:00,660
So in order to help you and I solve issues like this where we have some very specific of order of arguments
16
00:01:00,660 --> 00:01:04,650
that are expected, Darte has a feature called named Parameters.
17
00:01:05,040 --> 00:01:09,960
So rather than just passing in the suit or the rank as the first argument and the suit as the second,
18
00:01:10,350 --> 00:01:15,960
we can name the parameters that get passed into this card constructor and then we can provide those
19
00:01:15,960 --> 00:01:18,570
name parameters in any order that we wish.
20
00:01:19,110 --> 00:01:22,560
So let's do a little refactor here and you'll get a better idea of what I mean.
21
00:01:23,450 --> 00:01:29,840
I'm going to first start by adding a new line character in here like so and I'm going to put a new line
22
00:01:29,840 --> 00:01:30,920
after rank as well.
23
00:01:32,080 --> 00:01:38,980
OK, now here's the refractor, I'm going to say suit Kolan suit and rank, Colen rank.
24
00:01:40,270 --> 00:01:45,070
Now we immediately see an air message, but we'll just ignore that for a moment, what we just did is
25
00:01:45,070 --> 00:01:48,380
provided named parameters to the card constructor.
26
00:01:49,150 --> 00:01:55,420
Now, the left hand side of each of these colon's is the name of the argument to the name of the parameter
27
00:01:55,420 --> 00:01:57,370
that we're trying to provide to the constructor.
28
00:01:58,440 --> 00:02:04,290
The fact that the variable name is suit on the right hand side is not relevant at all, the name of
29
00:02:04,290 --> 00:02:07,960
the parameter and the actual value that we provide do not have to be identical.
30
00:02:08,280 --> 00:02:14,760
So in other words, I could change suit right here to my suit and change that right there to my suit
31
00:02:14,760 --> 00:02:15,150
as well.
32
00:02:16,340 --> 00:02:20,930
And now this would be completely equivalent to what we had before, the name that we provide to the
33
00:02:20,930 --> 00:02:24,170
parameter is not at all tied to the actual variable itself.
34
00:02:25,560 --> 00:02:29,850
Now we'll go down to our cart constructor, where we're going to massage it a little bit and tell it
35
00:02:29,850 --> 00:02:35,790
that it should expect to receive a named argument list, sit down at the bottom of the file.
36
00:02:36,630 --> 00:02:38,340
I'm going to find my card class.
37
00:02:40,230 --> 00:02:45,660
Here's my card constructor and then all we have to do to tell our card constructor that it should expect
38
00:02:45,660 --> 00:02:53,040
some named arguments is add a set of curly braces around this rink and this dot suit like so.
39
00:02:54,070 --> 00:02:58,000
So now, any time we create a new card, we're going to pass in.
40
00:02:59,170 --> 00:03:02,830
A variable named suit and a variable with name of rank.
41
00:03:03,850 --> 00:03:05,500
And then down inside this constructor.
42
00:03:06,640 --> 00:03:13,210
The constructor is going to look and see that it's being provided a list of named arguments and it's
43
00:03:13,210 --> 00:03:18,420
going to try to find in that list one argument named Reinke and one named suit at the.
44
00:03:18,460 --> 00:03:23,170
It's then going to extract those arguments and assign them to the appropriate instance variables.
45
00:03:24,090 --> 00:03:25,620
So now I should be able to run this code.
46
00:03:27,320 --> 00:03:31,040
And I see it correctly, two of diamonds, three of diamonds, four of diamonds and so on.
47
00:03:31,850 --> 00:03:37,820
So the benefit here is that by having these named parameters when we create our card is that we no longer
48
00:03:37,820 --> 00:03:40,760
have to remember the order in which we have to pass these in.
49
00:03:41,180 --> 00:03:48,050
I can freely rearrange this order as much as I please so I can put that rank first and then second,
50
00:03:48,650 --> 00:03:51,770
I can run this and everything is still going to work the way I expect.
51
00:03:52,690 --> 00:03:57,250
OK, so that's pretty much it, that's named arguments or name parameters in DART, so let's take a
52
00:03:57,250 --> 00:03:59,650
quick pause right here and continue in the next section.
5591
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.