1
00:00:01,170 --> 00:00:08,640
There are two main things we talk about when we say this is good code, but before I show you, what

2
00:00:08,640 --> 00:00:11,550
do you think good code is, think about that.

3
00:00:11,860 --> 00:00:15,510
What would you tell somebody if you're asking them to write good code?

4
00:00:16,430 --> 00:00:22,790
All right, I'll just give you the answer, you see, good code can be described in two things or two

5
00:00:23,060 --> 00:00:23,470
points.

6
00:00:24,350 --> 00:00:26,960
One is readability.

7
00:00:28,370 --> 00:00:37,200
Is your code just generally clean, can others understand your code and then we have scalable code?

8
00:00:37,700 --> 00:00:38,450
What does that mean?

9
00:00:39,080 --> 00:00:48,530
Well, the big O notation is what allows us to measure this idea of scalable code that can scale.

10
00:00:49,480 --> 00:00:53,920
Something that we're going to get into and you're going to become more familiar with as we go through

11
00:00:53,920 --> 00:00:59,800
the section, we're also going to talk about readable code throughout this entire course, but touch

12
00:00:59,800 --> 00:01:02,680
upon it a little bit more in the next section.

13
00:01:03,160 --> 00:01:08,950
But for now, because this is the big O section, we're focusing on this idea of scalable code.

14
00:01:09,400 --> 00:01:12,060
OK, what does this really mean, though?

15
00:01:12,850 --> 00:01:17,260
Well, I want you to imagine we have a task where we want to bake a cake.

16
00:01:17,920 --> 00:01:20,440
We have a recipe over here.

17
00:01:21,040 --> 00:01:26,350
And this recipe we're going to use in our kitchen to bake a cake.

18
00:01:27,130 --> 00:01:30,910
And there's a good way of baking a cake and a bad way.

19
00:01:30,940 --> 00:01:31,360
Right.

20
00:01:32,610 --> 00:01:40,080
We give it the instructions, that is the recipe, and hopefully this recipe and instructions work well

21
00:01:40,470 --> 00:01:46,030
with our kitchen so that we can bake a cake quickly and a good cake at that.

22
00:01:46,620 --> 00:01:48,960
Well, computers are machines.

23
00:01:49,900 --> 00:01:55,840
And these machines need to work in order to produce something for us and computers work in the same

24
00:01:55,840 --> 00:02:03,190
way we have these instructions that we give it through a code and these instructions that we give to

25
00:02:03,190 --> 00:02:10,780
our machines, our computers give these instructions that provide for us some sort of an output, for

26
00:02:10,780 --> 00:02:12,760
example, to turn on the light.

27
00:02:13,600 --> 00:02:18,180
We give the computer instruction to say, hey, turn on the light in our room.

28
00:02:18,790 --> 00:02:24,730
A coder is someone that gives these instructions just like there are many ways to take a cake into a

29
00:02:24,730 --> 00:02:31,930
kitchen, or just like there are many ways to bake a cake in the kitchen with many recipes, ingredients

30
00:02:31,930 --> 00:02:32,820
and instructions.

31
00:02:33,010 --> 00:02:36,180
There are many ways to solve a problem through code.

32
00:02:36,910 --> 00:02:40,240
They're efficient and inefficient ways to give instructions.

33
00:02:40,630 --> 00:02:42,310
So let's go to a coding example.

34
00:02:42,970 --> 00:02:44,860
I'm going to use Reppel Thudded.

35
00:02:45,280 --> 00:02:50,710
And if you are not familiar with this, make sure you check out the video that I've listed down below

36
00:02:50,710 --> 00:02:54,250
here, which explains how you can run your code in this course.

37
00:02:54,890 --> 00:02:56,110
I'm going to just log in.

38
00:02:58,190 --> 00:03:02,480
And I already have my JavaScript environment set up over here.

39
00:03:03,760 --> 00:03:10,780
And I prefer having the dark theme, I think that looks better on your eyes for you at least I hope

40
00:03:10,780 --> 00:03:15,930
you don't mind the darkness, but how can I demonstrate this idea of code?

41
00:03:16,900 --> 00:03:19,760
Let's do something fun here using JavaScript.

42
00:03:19,780 --> 00:03:22,480
I'm going to say const nimo.

43
00:03:23,690 --> 00:03:28,970
We have an array that contains the string nimo.

44
00:03:30,870 --> 00:03:33,420
And we want to create a function here.

45
00:03:34,820 --> 00:03:42,530
That is called Find Nemo, and this function is going to receive an array.

46
00:03:43,920 --> 00:03:50,970
And it's going to be a very simple function, we're going to create a loop that you'll see in most languages

47
00:03:52,080 --> 00:03:52,900
in JavaScript.

48
00:03:52,920 --> 00:03:58,980
We can do that easily by saying four and we'll give let I equals.

49
00:04:00,360 --> 00:04:00,880
Zero.

50
00:04:01,740 --> 00:04:11,880
And as long as I is smaller than the array length, that is the length of our array and then we're going

51
00:04:11,880 --> 00:04:12,660
to increment.

52
00:04:13,970 --> 00:04:15,020
I every time.

53
00:04:16,750 --> 00:04:22,660
Again, this isn't a JavaScript course, so hopefully this is familiar to you, any sort of loop that

54
00:04:22,660 --> 00:04:28,960
you want in your language, and we're just going to simply say that if Arae I.

55
00:04:30,120 --> 00:04:32,070
Equals Nimo.

56
00:04:33,370 --> 00:04:37,090
So if we find Nemo, we're just going to console DOT.

57
00:04:40,500 --> 00:04:42,060
Found Nemo.

58
00:04:42,720 --> 00:04:43,920
We're very excited, we found.

59
00:04:45,770 --> 00:04:47,030
All right, that's it.

60
00:04:47,480 --> 00:04:56,420
And if I just simply run the function now, find Nemo and we'll just give it the array nimo over here.

61
00:04:57,650 --> 00:05:03,740
And make sure that I spell lenth properly and we click Ron here.

62
00:05:05,290 --> 00:05:07,510
We have found Nimal on the right.

63
00:05:07,790 --> 00:05:09,610
Let me make this a little bit bigger so you can see.

64
00:05:10,680 --> 00:05:18,300
So we found Nemo, this is the instruction that we gave the computer, we told it that we have an array

65
00:05:18,690 --> 00:05:22,590
and we have a function, an action that we want to perform called Find Nemo.

66
00:05:22,860 --> 00:05:24,780
That takes an array, which is Nemo.

67
00:05:26,010 --> 00:05:28,680
It's going to receive this array.

68
00:05:29,710 --> 00:05:36,370
Then it's going to loop over the array, we're going to say that I is going to equal zero and because

69
00:05:36,370 --> 00:05:44,170
I have zero right now and the array length of nimo is one, we're going to go through the loop.

70
00:05:45,280 --> 00:05:51,440
We're going to check if Arae index of zero, which is naem over here.

71
00:05:51,490 --> 00:06:00,760
So this is going to turn into NIMO and because this is true, we're going to console log found nimo.

72
00:06:02,290 --> 00:06:04,970
Now, why did I just show you this example?

73
00:06:05,030 --> 00:06:08,080
Let me just bring this back to the way it was.

74
00:06:09,310 --> 00:06:16,750
I showed you this example because this is an instruction that we're giving our computer to find Nemo,

75
00:06:17,200 --> 00:06:19,530
you see, we call this the runtime.

76
00:06:19,990 --> 00:06:25,750
How long does it take to run a certain problem through a function or a task?

77
00:06:26,230 --> 00:06:33,100
How can we measure the big O or something like this or the efficiency of this code?

78
00:06:34,870 --> 00:06:39,850
In the next video, we're going to get a little bit deeper, we're going to try and measure the performance

79
00:06:39,880 --> 00:06:46,510
of this code and see what happens when the array gets larger and larger and we're going to tie things

80
00:06:46,510 --> 00:06:53,230
together as to what scaleable means and how big O allows us to measure the scalability.

81
00:06:54,410 --> 00:06:56,150
See you in the next video, bye bye.
