There are two main things we talk about when we say this is good code, but before I show you, what
do you think good code is, think about that.
What would you tell somebody if you're asking them to write good code?
All right, I'll just give you the answer, you see, good code can be described in two things or two
points.
One is readability.
Is your code just generally clean, can others understand your code and then we have scalable code?
What does that mean?
Well, the big O notation is what allows us to measure this idea of scalable code that can scale.
Something that we're going to get into and you're going to become more familiar with as we go through
the section, we're also going to talk about readable code throughout this entire course, but touch
upon it a little bit more in the next section.
But for now, because this is the big O section, we're focusing on this idea of scalable code.
OK, what does this really mean, though?
Well, I want you to imagine we have a task where we want to bake a cake.
We have a recipe over here.
And this recipe we're going to use in our kitchen to bake a cake.
And there's a good way of baking a cake and a bad way.
Right.
We give it the instructions, that is the recipe, and hopefully this recipe and instructions work well
with our kitchen so that we can bake a cake quickly and a good cake at that.
Well, computers are machines.
And these machines need to work in order to produce something for us and computers work in the same
way we have these instructions that we give it through a code and these instructions that we give to
our machines, our computers give these instructions that provide for us some sort of an output, for
example, to turn on the light.
We give the computer instruction to say, hey, turn on the light in our room.
A coder is someone that gives these instructions just like there are many ways to take a cake into a
kitchen, or just like there are many ways to bake a cake in the kitchen with many recipes, ingredients
and instructions.
There are many ways to solve a problem through code.
They're efficient and inefficient ways to give instructions.
So let's go to a coding example.
I'm going to use Reppel Thudded.
And if you are not familiar with this, make sure you check out the video that I've listed down below
here, which explains how you can run your code in this course.
I'm going to just log in.
And I already have my JavaScript environment set up over here.
And I prefer having the dark theme, I think that looks better on your eyes for you at least I hope
you don't mind the darkness, but how can I demonstrate this idea of code?
Let's do something fun here using JavaScript.
I'm going to say const nimo.
We have an array that contains the string nimo.
And we want to create a function here.
That is called Find Nemo, and this function is going to receive an array.
And it's going to be a very simple function, we're going to create a loop that you'll see in most languages
in JavaScript.
We can do that easily by saying four and we'll give let I equals.
Zero.
And as long as I is smaller than the array length, that is the length of our array and then we're going
to increment.
I every time.
Again, this isn't a JavaScript course, so hopefully this is familiar to you, any sort of loop that
you want in your language, and we're just going to simply say that if Arae I.
Equals Nimo.
So if we find Nemo, we're just going to console DOT.
Found Nemo.
We're very excited, we found.
All right, that's it.
And if I just simply run the function now, find Nemo and we'll just give it the array nimo over here.
And make sure that I spell lenth properly and we click Ron here.
We have found Nimal on the right.
Let me make this a little bit bigger so you can see.
So we found Nemo, this is the instruction that we gave the computer, we told it that we have an array
and we have a function, an action that we want to perform called Find Nemo.
That takes an array, which is Nemo.
It's going to receive this array.
Then it's going to loop over the array, we're going to say that I is going to equal zero and because
I have zero right now and the array length of nimo is one, we're going to go through the loop.
We're going to check if Arae index of zero, which is naem over here.
So this is going to turn into NIMO and because this is true, we're going to console log found nimo.
Now, why did I just show you this example?
Let me just bring this back to the way it was.
I showed you this example because this is an instruction that we're giving our computer to find Nemo,
you see, we call this the runtime.
How long does it take to run a certain problem through a function or a task?
How can we measure the big O or something like this or the efficiency of this code?
In the next video, we're going to get a little bit deeper, we're going to try and measure the performance
of this code and see what happens when the array gets larger and larger and we're going to tie things
together as to what scaleable means and how big O allows us to measure the scalability.
See you in the next video, bye bye.