text
stringlengths 1
81
| start
float64 0
10.1k
| duration
float64 0
24.9
|
|---|---|---|
is the array that's passed in.
| 756.47
| 1.46
|
And so we'll use that later to
use this thing called reset.
| 757.93
| 4.68
|
And so say we wanted to every single
time we added a value to this set,
| 762.61
| 3.78
|
we also wanted to log, hey,
we added a value to this set.
| 766.39
| 4.35
|
So we can just start writing
this method called add.
| 770.74
| 3.29
|
It takes a value just
like any other example.
| 774.03
| 2.114
|
But instead of implementing
add ourself, we're
| 776.144
| 1.916
|
just going to use the native
implementation of add.
| 778.06
| 2.25
|
And so that's where we use super.add.
| 780.31
| 1.6
|
So super, again, refers to the
class that we're extending.
| 781.91
| 4.57
|
And so when we invoke
super.add, it goes ahead
| 786.48
| 2.35
|
and does that using the
native implementation.
| 788.83
| 2.106
|
And then since we're going to extend
it with some additional logging.
| 790.936
| 2.874
|
We're just going to log, hey,
we added this val to the set.
| 793.81
| 3.09
|
And if you're not familiar with
this, if you use the backticks,
| 796.9
| 3.48
|
you can go ahead and add
variables in line, in the string,
| 800.38
| 2.85
|
and it'll go ahead and
substitute those in.
| 803.23
| 3.28
|
And so you see we added a
couple of other methods here.
| 806.51
| 2.36
|
We have to array, which is basically
saying, hey, I actually want the array,
| 808.87
| 3.48
|
and not the set.
| 812.35
| 0.7
|
And so we can just
return Array.from (this).
| 813.05
| 2.41
|
We're passing in the entire instance.
| 815.46
| 2.86
|
And lastly, we have a
reset, which is saying, hey,
| 818.32
| 3.27
|
I want the original set
that I had, or at least
| 821.59
| 4.71
|
a new set with equivalent value.
| 826.3
| 3.06
|
So you can return a new my set.
| 829.36
| 1.38
|
So notice you are referencing
my set inside that class.
| 830.74
| 3.72
|
We want a new one, and
we're going to pass in,
| 834.46
| 2.22
|
as the array here, the original array.
| 836.68
| 2.12
|
So this is an example of us extending
a class that already exists.
| 841.65
| 4.6
|
And as you see, if we want to
reference methods on that original,
| 846.25
| 4.38
|
we just use that super keyword.
| 850.63
| 3.48
|
So any questions on sets,
how we define them--
| 854.11
| 3.09
|
or sorry, classes and how we
define them, how we extend them?
| 857.2
| 4.2
|
So why might this be useful?
| 861.4
| 3.82
|
So as you guys are
doing on your project,
| 865.22
| 3.5
|
you're keeping track of
these things called to dos.
| 868.72
| 3.07
|
What if we actually
had a class for to do?
| 871.79
| 3.59
|
And when you invoke this constructor
on some configuration object,
| 875.38
| 4.419
|
what if it pulls out the text
and whether it's checked or not
| 879.799
| 2.541
|
and stores it as part of
[? its ?] class instance?
| 882.34
| 2.732
|
And say we want to
render it to the page.
| 885.072
| 1.708
|
What if we could just
return some HTML like this?
| 886.78
| 2.67
|
It would be quite handy, right?
| 891.699
| 1.291
|
And that actually is
our next topic, react.
| 892.99
| 5.46
|
So react is a JavaScript
library, and it allows
| 898.45
| 2.52
|
us to write declarative views that will
react to changes in data automatically.
| 900.97
| 4.716
|
It allows us to abstract complex
problems into smaller components,
| 905.686
| 3.754
|
and it allows us to write simple
code that still perform it.
| 909.44
| 3.29
|
And so I use this word in the
first bullet, declarative.
| 912.73
| 2.91
|
So what the heck does that mean?
| 915.64
| 2.5
|
So in CS50, we learned a paradigm
of coding called imperative.
| 918.14
| 5.93
|
And today we're going to talk
about declarative coding.
| 924.07
| 3.15
|
So the difference in
imperative and declarative
| 927.22
| 2.58
|
is like asking the difference
between how you do something
| 929.8
| 3.33
|
and actually what you want out of it.
| 933.13
| 3.21
|
So imperative programming
outlines a series of steps
| 936.34
| 3.27
|
to get to what you want,
whereas declarative,
| 939.61
| 2.94
|
you just say what you want.
| 942.55
| 2.2
|
And it's just an implementation
detail on how to get it.
| 944.75
| 4.07
|
And so we've learned a few different
languages through CS50 in this course.
| 948.82
| 3.57
|
A couple that come to mind
are HTML and JavaScript.
| 952.39
| 4.08
|
So in HTML, do we tell
the browser exactly how
| 956.47
| 3.48
|
we want to render all of these things?
| 959.95
| 3.24
|
Do we tell it exactly how we
want the DOM to be constructed?
| 963.19
| 4.26
|
No, we just tell it what we want.
| 967.45
| 2.61
|
And so HTML is considered a declarative
language, because you just say,
| 970.06
| 3.9
|
hey, I want this.
| 973.96
| 0.81
|
And browsers are in charge of
just giving you what you want.
| 974.77
| 5.69
|
Rather, with JavaScript, as you'll
see in your first project, when
| 980.46
| 2.95
|
you want to do anything to
the DOM with JavaScript,
| 983.41
| 2.4
|
you tell it, oh, first
get me a new element.
| 985.81
| 3.57
|
Call it a div.
| 989.38
| 1.41
|
Then do this.
| 990.79
| 1.5
|
Then maybe append it to the tree.
| 992.29
| 1.65
|
Then maybe add a class to it.
| 993.94
| 1.208
|
Maybe give it some inner HTML.
| 995.148
| 2.362
|
And so you're telling it exactly
what you want and how to do it.
| 997.51
| 2.75
|
And so that is the more
imperative way of programming.
| 1,000.26
| 4.018
|
So let's take this into an example.
| 1,007.35
| 1.9
|
Say we had a classical
guitar here, and say we
| 1,009.25
| 2.95
|
wanted to actually create this guitar.
| 1,012.2
| 3.75
|
So in an imperative way,
how would you describe that?
| 1,015.95
| 3.43
|
Well, you would say, oh,
I need a head over here.
| 1,019.38
| 3.41
|
I need to add some pegs to it.
| 1,022.79
| 1.26
|
Maybe I want the neck.
| 1,024.05
| 1.47
|
Maybe I add some frets to that.
| 1,025.52
| 2.085
|
Oh, I need to create the body and attach
them all and then maybe return that.
| 1,027.605
| 4.415
|
And what would be a more declarative
way of creating the guitar?
| 1,032.02
| 3.16
|
You just say, I want a guitar.
| 1,037.96
| 1.8
|
Maybe tune the strings to this.
| 1,039.76
| 1.319
|
And so an example in pseudo
code would be like this.
| 1,041.079
| 8.091
|
So say we have a guitar, and
say we have some function
| 1,049.17
| 2.92
|
called create element, similar to
what we have in the document in HTML.
| 1,052.09
| 5.86
|
And say we know exactly
what strings we want.
| 1,057.95
| 2.3
|
How might we go about
creating this guitar?
| 1,060.25
| 3.45
|
Well, first we might want to do
something like let's create a head.
| 1,063.7
| 3.24
|
Again, telling whoever's
listening exactly what we want.
| 1,073.15
| 4.7
|
And then maybe for 6 pegs, maybe we
want to start adding pegs to that head.
| 1,077.85
| 11.63
|
And so now we, in a very terse
manner, have a head with six pegs.
| 1,101.27
| 6.31
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.