In this video we're going to discuss why we care about tuples and when we might use them.
I'll be honest with you I am not a huge fan of tuples and I don't think you're going to really be using
them in a very regular basis with typescript.
There are a couple exceptions most notably I think that if you're ever working with a CSP file any one
represents say a single row you might reach out to a tuple will actually work at the CSP file later
on inside this course and so you'll see a great example of that in action.
So let me tell you exactly why I don't think you're going to be using tuples that often at the bottom
this file on when you declare a new variable called Car specs like so and I'm going to assign it some
data that has a real important meaning around a car like some specifications around a car.
So I'm going to assign it a tuple of four hundred three fifty like so I'll make sure that I annotate
the type on here to make sure it's really clear that this is a tuple so it's a number and a number like
so.
Okay.
So here's the question what do these numbers mean to you.
I mean looking at this line of code right here in isolation what do those numbers mean.
Clearly it has something to do with these specs around a car.
But what is the purpose of these numbers.
Well for us as engineers I don't think that we can really look at this line of code and understand what
is going on here.
We know that there are two values.
We know that they are numbers but that's pretty much it so let's try writing out that same type of data
structure right here but instead as an object.
So if I write out a very similar variable right here maybe I'll call it car stats this time I'm gonna
make it an object and because it's an object this time I have to add in a key and a value.
So for the value 400 I'm going to give a key of horsepower horsepower.
There we go.
And then for the three three five four I'll put in weight like so.
All right.
So what am I trying to illustrate here.
Well if we use a tuple to represent some meaningful data it's really hard for you and I's engineers
to look at this value right here and understand what we are trying to say however in an object format
right here because we are forced to put in a key.
It is immediately obvious what we are working with.
I can look at this object right here and understand 0 horsepower 400.
Got it.
And then for weights This is the weight of maybe a car in pounds three thousand three hundred fifty
four pounds.
So when we make use of an object to model a record it's really clear what we were working with at one
glance but when we are working at that table much harder to understand exactly what is going on at a
glance so honestly I think that in general any time we want to model a record or record it in our application
somehow we're going to stick with a javascript convention of reaching for an object as opposed to a
temple.
Now like I said there are some corner cases where we might want to use this in some types of applications
and we will see an example of it later on INSIDE THIS COURSE.
Actually it's one of the first two or three applications we're going to work on.
All right.
So I'm sorry to teach you about troubles and then say hey we're never going to use them but nonetheless
it is a feature of typescript that is very prominently featured in the official documentation.
So I just want to make sure you have at least a passing idea of what these type of things are all about.
So let's take a quick pause right here.
We're going to move on to our next topic in the next video.