In this video, we're going to follow up on a raise by discussing a very similar data structure called
a tuple, and you'll sometimes also hear this pronounced as tuple, totally up to you, either tuple
or tuple.
Either way, you want to do it.
So, as usual, definition examples and so on.
All right.
So first off, quick definition.
So when we are working with a tuple or a tuple, we have something that looks very similar to an array,
very, very similar.
But the big difference here is that we are going to have every element inside of this array looking
thing represent one specific property about some record.
So whereas an array tells us a bunch of different records or organizes a collection of different records,
a tuple usually contains multiple different properties to describe one single thing.
And as a follow up to that, usually inside of a couple, we will mix and match many different types
of data inside there.
So let's take a look at a quick example.
All right.
I want you to imagine that we've got some object like the one you see right here.
And the goal of this object is to represent a drink, like, in this case, soda or pop, whatever you
want to refer to it as.
So maybe inside this object, we have a color property that is a string of brown carbonated that is
a billion of true and sugar that is meant to represent the sugar content of the soda in grams.
So that will be a number here.
So as you might guess, this would represent maybe like Coca-Cola or Pepsi or something like that.
So representing a drink or a soda with an object like this, I think makes a lot of sense.
If you're coming particularly from a JavaScript background, we've got one object to represent one drink.
And this object has some properties that describe what is going on with this singular drink.
Now, just for fun, I want to take this object right here, and I just want to try to represent it
with a slightly different data structure.
Let's try to represent this object with an array instead.
So how can we do that?
Well, maybe we would say that we would take each these values.
So like Brown.
True.
And then 40 and stick them into this array like so.
So now we have a slightly different looking data structure that still represents a drink.
And turning this into this, a raid right here, we have lost a little bit of information.
In other words, you and I as developers can very easily look at a object declaration like this right
here and very quickly understand, OK, the colors brown carbonate is true and sugar is 40.
When we start to represent this object as an array, we've lost those different property labels on here.
And so you and I as developers would have to memorize the fact that the first element inside this array
is supposed to be a string representing the color.
The second element is supposed to be a boolean representing whether or not the drink is carbonated.
And then the third element inside there is a number representing these sugar content.
So the big difference between representing this as an object and something that looks like an array
is really just that loss of information in these labels no longer is our code really self labeling.
Instead, we have to kind of memorize the order of properties inside of appear.
So this is exactly what a tuple is, we have what looks like an array and we put in our property values
into that array in a very specific order.
So the ordering part is really critical.
If we start to arbitrarily swap around elements inside of here, we are no longer going to understand
which different value represents which property.
So if you and I have memorized, like as developers, that this array is always supposed to tell us
the color, then the carbonation and then the sugar content, and we swap some elements inside of here
and we don't have those labels.
Now, this is kind of a meaningless record because we're now trying to indicate that our color is 40.
Carbonation is true and sugar content is brown.
So when we work at the tuple, we have a fixed series of elements or a fixed order, I should say.
All right, now, let's take a quick pause right here, we're going to come back to the next section,
get some more examples around tuples and start to write out some code around them.
So quick pause and I'll see you in just a minute.