In the previous video, we learned that Opie is what we call a paradigm, a way to think about our code
and structure our code.
And I'm going to link to this excellent article from Wikipedia about the history of programming languages.
You see, we started with basic programming languages.
We have things like assembly language that was really low level, really close to machine code.
We had things like COBOL and then we slowly as we started writing more and more code in the sixties
and seventies, we started establishing some of these fundamental paradigms.
And one of the big paradigms that came to be, especially with the Smalltalk programming language,
was this idea of object oriented programming or an object oriented language.
You see, up until that point, we wrote what we call procedural code.
What that means is that if we look at a Python file, for example, a procedural code was just like
a procedure.
We simply had lines one through, let's say 100, and we just went from the top of the line to the bottom
of the line.
We had conditionals, maybe loops, but everything was do this, do that.
It was us telling the machine, Hey, just do exactly this one.
I'm about to tell you with the introduction of object oriented paradigms.
This changed a bit.
We started saying, Hey, let's model something in our code that represents a real world object.
For example, if I'm about to code a car, I would create a car object that has data on what color it
is, what type of engine it has, how many seats it has, but also actions like methods that we can
take on it, such as the car can go forward, it can go backward, it can open the door.
And instead of having these line by line procedural code, we can think in terms of models, real world
blueprints, because as humans we organize things.
Think of a room.
Think of a factory by organizing things and having different groups in a specific location, working
together.
That's a better way to think as well as to run things.
So how would this look in Python?
Well, Python is an object oriented language or can be, which means that it's able to support open
ideas.
This idea of objects and modeling and we've seen this when we use the type, we see that everything
is an object because we use this class keyword.
But what is this class keyword in Python?
I can create my own data, type my own class by simply saying class, and then afterwards I can name
it whatever I want.
Let's say class.
Big.
Object.
Now right away.
You see here that the naming convention is different than what we've seen before.
We're going to make sure that it's capitalized, which is the standard.
We want to let programmers know that this is going to be a class and we're not using the snake case.
We're using what we call camel case, which is every new word is a capital letter.
And then here we use the colon, and then in here we write our code.
Now, I'm not going to write the code right now.
I'm just going to pass.
But right there, I've just created a new class so that if I do, let's say, for example.
Type.
Big Object and I click Run.
Well, I still get type because right now what we've created is this class, which is a blueprint,
but we haven't actually created the object.
I know the wording can get confusing, but bear with me.
I will explain this.
We can now create, let's say, object one equals to big object and then run this class.
So that if I do type object here, object one and I click run.
I get class.
Big object.
You can ignore the main here for now because we're going to talk about it later.
But you see here that I've just created my own object.
Now, let's think about what just happened here, because it is a lot to understand.
You see an object oriented programming, there's this idea of a class and an object.
Now, a class is this.
It's the blueprint.
The blueprint of what we want to create.
What are the basic attributes that is properties that our class has?
What are some basic methods or actions that our class can take?
And then from this blueprint, I'm able to create different objects over and over using this as the
building block.
So this blueprint is what we call a class.
Which we define with the class keyword, and this class can be instantiated.
That is the action of creating different instances.
And what are these instances?
These are all objects.
Now the naming here is something that you're going to have to get used to.
And all object oriented programming languages have this language.
So you'll just have to understand what somebody says.
Hey, I just instantiated a class.
It means, hey, I just created a new instance, a new object.
So looking at this diagram, let's go back to the code that we just wrote.
We've created here a class or a blueprint.
And then here this double bracket is us instantiating the class and saying, Hey class, use whatever
you have code in here and instantiate it and create a new object.
So we're creating a new object by instantiating this class.
And this is exactly what we're doing with something like a list, right?
I can create multiple lists over and over and over.
And every time I create a list, I have access to all of these methods and sometimes even attributes
that I can use.
And this way I save a lot of time instead of coding it myself.
And in the same way I can create multiple objects here.
Object to.
Object three.
Just like that.
And now I have three different objects that I can use based on this blueprint.
Now, the blueprint right now doesn't have anything because well, I can add code here later and we're
going to do that in the next video.
But the beauty is let's think about efficiency here.
You see the blueprint itself.
The class is going to be stored in memory.
So Python interpreter is going to say, hey, big object is going to be the blueprint for this.
So I'm going to store all that code in memory.
But every time I create an object, I don't have to rewrite the code or do anything like that.
I can simply say, Hey, go in memory to where big object is and just run that code so that again we're
keeping our code dry.
We have one place that allows us to instantiate our code into objects.
Let's take a break and expand on this class in the next video.