text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
>> So at the end of the day,
program is identical. | 7,176.89 | 2.27 |
But notice all of this stuff
could even be in another file. | 7,179.16 | 3.66 |
Indeed, I don't know at the
moment how printf is implemented. | 7,182.82 | 2.8 |
>> I don't know at the moment how get
string, or get int, or get float | 7,185.62 | 2.36 |
are implemented. | 7,187.98 | 0.666 |
And I don't want to
see them on my screen. | 7,188.646 | 2.284 |
As it is, I'm starting to focus on
my program, not those functions. | 7,190.93 | 4.39 |
>> And so, indeed, as soon as you
start factoring code like this out, | 7,195.32 | 3.75 |
could we even move cough
to a separate file? | 7,199.07 | 2.327 |
Someone else could implement it. | 7,201.397 | 1.333 |
And you and your program become the
very beautiful, and very readable, | 7,202.73 | 4.08 |
arguably, really four
line program right there. | 7,206.81 | 4.02 |
>> So let's go ahead now
and make one more change. | 7,210.83 | 2.68 |
Notice that my prototype
has to change up top. | 7,213.51 | 2.67 |
So let me fix that so
I don't get yelled at. | 7,216.18 | 2.21 |
>> Make cough, let me run cough once
more, still doing the same thing. | 7,218.39 | 4.19 |
But now, notice we have an
ingredient for one final version. | 7,222.58 | 3.43 |
You know what? | 7,226.01 | 0.93 |
I don't want to just cough, necessarily. | 7,226.94 | 2.1 |
I want to have something more general. | 7,229.04 | 1.762 |
So you know what? | 7,230.802 | 0.708 |
I want to do this. | 7,231.51 | 0.94 |
I want to have, much like Scratch
does, a say block, but not just | 7,232.45 | 4.69 |
say something some number of times. | 7,237.14 | 1.54 |
I want it to say a very specific string. | 7,238.68 | 2.83 |
And, therefore, I don't
want it to just say cough. | 7,241.51 | 2.34 |
I want it to say whatever
string is passed in. | 7,243.85 | 3.81 |
>> So notice, I've generalized
this so that now | 7,247.66 | 2.3 |
say feels like a good name
for this, like Scratch, | 7,249.96 | 3.15 |
takes two arguments, unlike Scratch. | 7,253.11 | 2.42 |
One is a string. | 7,255.53 | 1.04 |
One is an int. | 7,256.57 | 0.73 |
>> And I could switch them. | 7,257.3 | 0.83 |
I just kind of like the idea of
say the string first, and then | 7,258.13 | 2.583 |
how many times later. | 7,260.713 | 1.227 |
Void means it still
doesn't return anything. | 7,261.94 | 2.03 |
These are just visual side
effects, like with [? Jordan, ?] | 7,263.97 | 2.458 |
a verbal side effect of yelling. | 7,266.428 | 1.812 |
It still does something n times,
0 up to, but not equal to n. | 7,268.24 | 4.39 |
This means n total times. | 7,272.63 | 1.91 |
And then just print out
whatever that string is. | 7,274.54 | 2 |
So I've really generalized
this line of code. | 7,276.54 | 2.52 |
So now, how do I implement
the cough function? | 7,279.06 | 3.4 |
>> I can do void cough. | 7,282.46 | 3.06 |
And I can still take in how
many times you want to cough. | 7,285.52 | 2.981 |
But you know what? | 7,288.501 | 0.749 |
I can now punt to say. | 7,289.25 | 1.99 |
>> I can call say with the
word cough, passing in n. | 7,291.24 | 5.3 |
And if I want to also implement,
just for fun, a sneeze function, | 7,296.54 | 3.87 |
I can sneeze some number of times. | 7,300.41 | 1.88 |
And I can keep reusing n, because
notice that m in this context or scope | 7,302.29 | 5.01 |
only exists within this function. | 7,307.3 | 2.17 |
>> And n in this context only
exists within this function here. | 7,309.47 | 3.297 |
So we'll come back to
these issues of scope. | 7,312.767 | 1.833 |
And here, I'm just going to say,
achoo, and then n times, semi-colon. | 7,314.6 | 6.56 |
>> And now, I just need to borrow
these function signatures up here. | 7,321.16 | 3.18 |
So cough is correct. | 7,324.34 | 1.95 |
Void sneeze is correct now. | 7,326.29 | 3.8 |
>> And I still just need say. | 7,330.09 | 2.3 |
So I'm going to say, say
string s, int n, semi-colon. | 7,332.39 | 6.6 |
So I've over-engineered the
heck out of this program. | 7,338.99 | 3.02 |
>> And this doesn't
necessarily mean this is | 7,342.01 | 1.75 |
what you should do when writing
even the simplest of programs. | 7,343.76 | 2.583 |
Take something that's obviously
really simple, really short, | 7,346.343 | 2.937 |
and re-implement it
using way too much code. | 7,349.28 | 2.52 |
But you'll actually see, and in
time look back on these examples, | 7,351.8 | 2.76 |
and realize, oh, those are the steps
we took to actually generalize, | 7,354.56 | 4.05 |
to factor something out,
until at the end of the day | 7,358.61 | 2.187 |
my code is actually pretty reasonable. | 7,360.797 | 1.583 |
Because if I want to cough three
times then sneeze three times, | 7,362.38 | 3.58 |
I'm simply going to rerun this,
program make cough, and run cough. | 7,365.96 | 4.46 |
And I have three coughs
and three sneezes. | 7,370.42 | 3.2 |
>> And so this is a basic
paradigm, if you will, | 7,373.62 | 2.37 |
for how we might go about
actually implementing a program. | 7,375.99 | 4.12 |
But let's just see now what it is
we've been doing all of this time, | 7,380.11 | 3.11 |
and what some of the final pieces
are behind this simple command. | 7,383.22 | 3.72 |
At the end of the day, we've
been using Clang as our compiler. | 7,386.94 | 2.68 |
We've been writing source
code, converting it | 7,389.62 | 1.874 |
via Clang into machine code. | 7,391.494 | 1.326 |
>> And we've been using Make just
to facilitate our keystrokes so | 7,392.82 | 2.72 |
that we don't have to remember
those incantations of Clang itself. | 7,395.54 | 5.2 |
But what is Make actually doing? | 7,400.74 | 1.9 |
And, in turn, what is
Clang actually doing? | 7,402.64 | 2.11 |
>> It turns out, though we have simplified
today's discussion by saying, | 7,404.75 | 4.04 |
you take source code, pass it as
input to a compiler, which gives you | 7,408.79 | 4.3 |
output of machine
code, turns out there's | 7,413.09 | 2.66 |
a few different steps inside there. | 7,415.75 | 1.67 |
And compiling happens to be the umbrella
term for a whole bunch of steps. | 7,417.42 | 4.52 |
But let's just tease
this out really quickly. | 7,421.94 | 2.03 |
>> It turns out that we've been doing
more things every time I run a program, | 7,423.97 | 4.1 |
or every time I compile a program today. | 7,428.07 | 2.92 |
So preprocessing refers to
this-- anything in a C program, | 7,430.99 | 4.03 |
as we'll see again and again,
that starts with this hash symbol, | 7,435.02 | 3.7 |
or the hashtag symbol here, means
it's a preprocessor directive. | 7,438.72 | 4.6 |
That means, in this case, hey
computer, do something with this file | 7,443.32 | 4.01 |
before you actually compile my own code. | 7,447.33 | 2.1 |
>> In this case, hash include is,
essentially, C's way of saying, | 7,449.43 | 5.79 |
hey computer, go get the contents
of CS50.h and paste them here. | 7,455.22 | 4.105 |
Hey computer, go get the
contents of standard IO.h, | 7,459.325 | 2.845 |
wherever that is on the
hard drive, paste it here. | 7,462.17 | 2.52 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.