1
00:00:00,920 --> 00:00:04,820
In this video, we're going to discuss why we care about tuples and when we might use them.

2
00:00:05,390 --> 00:00:10,100
And I'll be honest with you, I am not a huge fan of tuples, and I don't think you're going to really

3
00:00:10,100 --> 00:00:12,450
be using them in a very regular basis with TypeScript.

4
00:00:12,860 --> 00:00:14,300
There are a couple of exceptions.

5
00:00:14,420 --> 00:00:19,310
Most notably, I think that if you're ever working with a CSV file, any one represents, say, a single

6
00:00:19,310 --> 00:00:24,590
row, you might reach out to a tuple will actually work at the CSV file later on inside this course.

7
00:00:24,590 --> 00:00:27,160
And so you'll see a great example of that in action.

8
00:00:27,530 --> 00:00:32,390
So let me tell you exactly why I don't think you're going to be using tuples that often at the bottom

9
00:00:32,390 --> 00:00:37,970
of this file I'm going to declare a new variable called car specs like so and I'm going to assign it

10
00:00:37,970 --> 00:00:43,790
some data that has a real important meaning around a car, like some specifications around a car.

11
00:00:44,360 --> 00:00:49,370
So I'm going to assign it a tuple of four hundred three, three fifty for like.

12
00:00:49,370 --> 00:00:54,140
So I'll make sure that I annotate the type on here to make sure it's really clear that this is a tuple.

13
00:00:54,140 --> 00:00:56,270
So it's a number and a number like.

14
00:00:56,270 --> 00:00:58,550
So OK, so here's the question.

15
00:00:59,090 --> 00:01:00,830
What do these numbers mean to you?

16
00:01:01,140 --> 00:01:05,120
I mean, looking at this line of code right here in isolation, what do those numbers mean?

17
00:01:05,120 --> 00:01:09,450
Clearly, it has something to do with these specs around a car, but what is the purpose of these numbers?

18
00:01:10,160 --> 00:01:14,840
Well, for us as engineers, I don't think that we can really look at this line of code and understand

19
00:01:14,840 --> 00:01:15,780
what is going on here.

20
00:01:16,130 --> 00:01:17,630
We know that there are two values.

21
00:01:17,630 --> 00:01:20,240
We know that they are numbers, but that's pretty much it.

22
00:01:21,350 --> 00:01:26,860
So let's try writing out that same type of data structure right here, but instead as an object, so

23
00:01:26,900 --> 00:01:31,430
if I write out a very similar variable right here, maybe I'll call it car stats.

24
00:01:31,430 --> 00:01:33,530
This time I'm going to make it an object.

25
00:01:33,530 --> 00:01:37,370
And because it's an object, this time I have to add in a key and a value.

26
00:01:38,160 --> 00:01:42,440
So for the value of 400, I'm going to give a key of horsepower.

27
00:01:44,280 --> 00:01:45,850
Horsepower, there we go.

28
00:01:46,410 --> 00:01:50,190
And then for the three three, five four, I'll put in weight like so.

29
00:01:51,860 --> 00:01:53,660
All right, so what am I trying to illustrate here?

30
00:01:53,930 --> 00:01:59,840
Well, if we use a tuple to represent some meaningful data, it's really hard for you and I as engineers

31
00:01:59,840 --> 00:02:03,260
to look at this value right here and understand what we are trying to say.

32
00:02:04,310 --> 00:02:09,770
However, in an object format right here, because we are forced to put in a key, it is immediately

33
00:02:09,770 --> 00:02:11,470
obvious what we are working with.

34
00:02:11,480 --> 00:02:15,770
I can look at this object right here and understand, oh, horsepower, 400.

35
00:02:15,770 --> 00:02:16,340
Got it.

36
00:02:16,700 --> 00:02:21,800
And then for weight, this is the weight of maybe a car in pounds three thousand three hundred fifty

37
00:02:21,800 --> 00:02:22,650
four pounds.

38
00:02:23,180 --> 00:02:28,700
So when we make use of an object to model a record, it's really clear what we were working with at

39
00:02:28,730 --> 00:02:29,780
one glance.

40
00:02:30,140 --> 00:02:34,730
But when we are working at the tuple, much harder to understand exactly what is going on at a glance.

41
00:02:35,650 --> 00:02:41,320
So honestly, I think that in general, any time we want to model a record or record it in our application,

42
00:02:41,330 --> 00:02:46,450
somehow we're going to stick with a JavaScript convention of reaching for an object as opposed to a

43
00:02:46,450 --> 00:02:46,810
tuple.

44
00:02:47,470 --> 00:02:52,240
Now, like I said, there are some corner cases where we might want to use this in some types of applications

45
00:02:52,240 --> 00:02:54,390
and we will see an example of it later on inside.

46
00:02:54,400 --> 00:02:58,840
Of course, actually, that's one of the first two or three applications we're going to work on.

47
00:02:59,750 --> 00:03:03,170
All right, so I'm sorry to teach you about troubles and then say, hey, we're never going to use them,

48
00:03:03,170 --> 00:03:10,100
but nonetheless, it is a feature of typescript that is very prominently kind of featured in the official

49
00:03:10,100 --> 00:03:11,000
documentation.

50
00:03:11,000 --> 00:03:15,260
So I just want to make sure you have at least a passing idea of what these type of things are all about.

51
00:03:15,830 --> 00:03:17,100
So let's take a quick pause right here.

52
00:03:17,120 --> 00:03:19,550
We're going to move on to our next topic in the next video.

