Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,830 --> 00:00:05,900
In the last section, we laid out a couple of different rules around Dart's type system in the section,
2
00:00:05,900 --> 00:00:08,720
we're going to talk just a little bit more about types in particular.
3
00:00:08,720 --> 00:00:12,230
We're going to look at some of the very basic types that are available to us in DART.
4
00:00:13,160 --> 00:00:13,980
All right, here we go.
5
00:00:14,240 --> 00:00:19,010
So on the left hand side of listed out a couple of very basic types and then on the right hand side,
6
00:00:19,010 --> 00:00:21,170
we've got some example values of each one.
7
00:00:21,950 --> 00:00:24,440
You and I have already taken a look at the string tight.
8
00:00:24,860 --> 00:00:29,280
A string type is a series of characters that get put together into one value.
9
00:00:29,780 --> 00:00:33,070
So an example of a string type would be, hi, how's it going?
10
00:00:33,080 --> 00:00:34,160
And that's great.
11
00:00:36,050 --> 00:00:41,150
One of the other very basic types that we're going to make use of in many of our programs is the int'l
12
00:00:41,150 --> 00:00:49,220
type as well, which is short for integer and integer is any number negative, zero or positive that
13
00:00:49,220 --> 00:00:51,680
does not have a decimal associated with it.
14
00:00:52,220 --> 00:00:57,560
So an example of an inch would be zero negative nine nine nine or eight hundred and seventy six thousand.
15
00:00:59,360 --> 00:01:03,300
One of the last very common types that we're going to work with quite a bit is the double type.
16
00:01:03,710 --> 00:01:07,210
This is a number that has a decimal associated with it.
17
00:01:07,580 --> 00:01:11,780
So the big difference between integer and double is the presence of some decimal.
18
00:01:12,760 --> 00:01:17,920
Examples of doubles would be zero point zero zero one negative, ninety nine point eight one four.
19
00:01:17,950 --> 00:01:19,060
And you get the idea.
20
00:01:20,620 --> 00:01:25,780
Now, besides these very basic types, we also have this dynamic type, which we briefly discussed in
21
00:01:25,780 --> 00:01:31,270
the last section, the dynamic type down here is still technically a type in dart.
22
00:01:31,840 --> 00:01:37,090
The dynamic type means to say we have a variable that can hold any value that we wish.
23
00:01:38,060 --> 00:01:43,460
So if we had a variable with a type of dynamic associated with it, that variable could reference any
24
00:01:43,460 --> 00:01:49,760
type of value, like the string right here of high, the double negatives point zero zero zero four
25
00:01:49,850 --> 00:01:51,410
or the integer 90.
26
00:01:53,430 --> 00:01:57,240
Now, the last thing I want to mention very briefly about types before we move on to our next topic
27
00:01:57,600 --> 00:02:00,810
is have a quick discussion about why we care about types at all.
28
00:02:01,380 --> 00:02:05,640
This is probably one of the more important things to talk about, especially if you're coming from a
29
00:02:05,640 --> 00:02:07,810
dynamic language like, say, JavaScript.
30
00:02:08,190 --> 00:02:12,150
So let's very briefly talk about some of the benefits of using a type system.
31
00:02:13,370 --> 00:02:18,680
One of the most market benefits is that whenever we use a type system, there is the possibility of
32
00:02:19,340 --> 00:02:21,430
improving the performance of our application.
33
00:02:22,220 --> 00:02:28,670
Even when you use JavaScript, which is a dynamic language when that JavaScript code is executed, the
34
00:02:28,670 --> 00:02:34,060
interpreter that's executing that code is technically still doing some type, checking behind the scenes.
35
00:02:34,490 --> 00:02:40,010
And so any time we use a dynamic, dynamic language, there is a performance penalty associated with
36
00:02:40,010 --> 00:02:40,220
it.
37
00:02:40,910 --> 00:02:45,500
By using a type system, we have the possibility of getting some improved performance.
38
00:02:47,190 --> 00:02:52,940
Next up, it tends to be a little bit easier to work on large projects when they use a strong type system.
39
00:02:53,800 --> 00:02:58,840
So if we're working on some very large project where we have to make use of some code written by another
40
00:02:58,840 --> 00:03:05,200
engineer, it will be a lot easier if we could get a better idea of what the structure of data is that
41
00:03:05,200 --> 00:03:06,340
comes back from some code.
42
00:03:06,370 --> 00:03:08,110
There's whenever we execute it.
43
00:03:08,840 --> 00:03:14,440
So if we're working on a large project with many engineers or even just a few, it tends to be a little
44
00:03:14,440 --> 00:03:17,770
bit easier to work with a language that has strong typing.
45
00:03:19,350 --> 00:03:25,350
Next, there tends to be slightly less of a need to write unit tests around any language that has strong
46
00:03:25,350 --> 00:03:26,530
typing associated with it.
47
00:03:27,210 --> 00:03:32,250
For example, if we're making use of Ruby or JavaScript, we might want to run a test that says that
48
00:03:32,250 --> 00:03:36,810
any time we run some particular function, we always get back an array or a string or an integer.
49
00:03:38,010 --> 00:03:42,960
So if we're using JavaScript, Ruby, we definitely would want to write a test like that to make sure
50
00:03:42,960 --> 00:03:48,480
that in fact, yes, we get back an array or a string or whatever it is, but when we're making use
51
00:03:48,480 --> 00:03:53,430
of a strongly typed language with Dart, we get a little bit more assurance that whenever we say that
52
00:03:53,430 --> 00:03:56,930
some function is going to return, some specific value, chances are, yep.
53
00:03:57,030 --> 00:03:59,340
In fact, it's going to return that type of value.
54
00:04:00,980 --> 00:04:06,710
Finally and makes life a little bit easier for finding very simple errors, for example, if we go back
55
00:04:06,710 --> 00:04:11,840
over to our dart pad project over here, let's say that right before we try to print up the string right
56
00:04:11,840 --> 00:04:17,089
here, we tried to retrieve the length of this string that we return from the mining function.
57
00:04:17,720 --> 00:04:24,530
So if I wanted to get the length of some particular string, I could write out name length like so.
58
00:04:25,680 --> 00:04:30,960
Now, when I write this code out right here, Darte has the ability to look at the type of variable
59
00:04:31,170 --> 00:04:36,660
that this very early in the type of value that this variable is referencing, DART knows that it is
60
00:04:36,660 --> 00:04:39,060
of type string Daquan.
61
00:04:39,060 --> 00:04:43,170
Then go check to see if String has a length property associated with it.
62
00:04:43,350 --> 00:04:45,090
And in this case, yes, it does.
63
00:04:46,000 --> 00:04:51,050
If we instead returned an integer from the mining function down here instead, like, say, INT.
64
00:04:52,190 --> 00:04:54,350
And then returned the number one, two, three.
65
00:04:55,330 --> 00:04:59,980
Now, the we're getting a nasty, nastier message from this line of code, because Dart is able to know
66
00:04:59,980 --> 00:05:05,690
that name is now storing an integer and an integer does not have a length property associated with it.
67
00:05:06,310 --> 00:05:11,380
So, again, by using a type system, we get a little bit better ability to find very simple errors
68
00:05:11,380 --> 00:05:12,670
like that inside of our code.
69
00:05:13,330 --> 00:05:14,710
Now, really quickly, back over here.
70
00:05:14,740 --> 00:05:16,690
I am going to undo those changes I made.
71
00:05:17,110 --> 00:05:17,530
Very good.
72
00:05:18,410 --> 00:05:22,430
OK, so in this section, we spoke about some of the very basic types that are available to us inside
73
00:05:22,430 --> 00:05:26,030
of DART, and we also spoke about why we care about using type systems at all.
74
00:05:26,630 --> 00:05:31,040
So let's continue in the next section and we're going to take a look at the very last line of code inside
75
00:05:31,040 --> 00:05:33,090
of our program, the print statement.
76
00:05:33,320 --> 00:05:35,410
So quick break and we'll see you in just a minute.
8267
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.