text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
>> It's not all that inspiring. | 2,622.26 | 1.436 |
And, indeed, these first few
examples will take some time | 2,623.696 | 2.374 |
to ramp up in excitement. | 2,626.07 | 1.44 |
But we have so much more
control now, in fact. | 2,627.51 | 2.344 |
And we're going to very
quickly start layering | 2,629.854 | 1.916 |
on top of these basic primitives. | 2,631.77 | 2.1 |
>> But first, let's understand
what the limitations are. | 2,633.87 | 2.5 |
In fact, one of the things
Scratch doesn't easily | 2,636.37 | 2.25 |
let us do is really look
underneath the hood, | 2,638.62 | 2.37 |
and understand what a
computer is, what it can do, | 2,640.99 | 2.75 |
and what its limitations are. | 2,643.74 | 1.51 |
And, indeed, that lack of
understanding, potentially, long-term | 2,645.25 | 3.33 |
can lead to our own mistakes-- writing
bugs, writing insecure software that | 2,648.58 | 3.94 |
gets hacked in some way. | 2,652.52 | 1.36 |
>> So let's take some steps toward
understanding this a little better by | 2,653.88 | 3.25 |
way of, say, the following example. | 2,657.13 | 2.58 |
I'm going to go ahead and implement
real quick a program called Adder. | 2,659.71 | 3.84 |
Like, let's add some numbers together. | 2,663.55 | 1.584 |
And I'm going to code some corners
here, and just copy and paste | 2,665.134 | 2.666 |
where I was before, just
so we can get going sooner. | 2,667.8 | 2.47 |
So now I've got the basic beginnings
of a program called Adder. | 2,670.27 | 2.82 |
>> And let's go ahead and do this. | 2,673.09 | 1.58 |
I'm going to go ahead and
say, intx gets get int. | 2,674.67 | 4.01 |
And you know what? | 2,678.68 | 0.75 |
Let's make a better user experience. | 2,679.43 | 1.56 |
>> So let's just say x is, and effectively
prompt the user to give us x. | 2,680.99 | 4.75 |
And then let me go ahead and say, printf
how about y is, this time expecting | 2,685.74 | 4.86 |
two values from the user. | 2,690.6 | 2.54 |
And then let's just go ahead and
say, printf, the sum of x and y is. | 2,693.14 | 6.619 |
And now I don't want to do percent s. | 2,699.759 | 1.541 |
I want to do percent i, backslash
n, and then plug in sum value. | 2,701.3 | 7.78 |
>> So how can I go about doing this? | 2,709.08 | 1.54 |
You know what? | 2,710.62 | 0.65 |
I know how to use variables. | 2,711.27 | 1.57 |
Let me just declare a new one, int z. | 2,712.84 | 2.3 |
>> And I'm going to take a guess here. | 2,715.14 | 1.63 |
If there are equal signs in this
language, maybe I can just do x plus y, | 2,716.77 | 4.7 |
so long as I end my
thought with a semi-colon? | 2,721.47 | 2.19 |
Now I can go back down here, plug in z,
finish this thought with a semi-colon. | 2,723.66 | 4.51 |
And let's see now, if these
sequences of lines-- x is get int. | 2,728.17 | 4.99 |
Y is get int. | 2,733.16 | 1.61 |
>> Add x and y, store the value in z--
so, again, remember the equal sign | 2,734.77 | 3.21 |
is not equal. | 2,737.98 | 0.58 |
It's assignment from right to left. | 2,738.56 | 2.54 |
And let's print out that the sum
of x and y is not literally z, | 2,741.1 | 4.08 |
but what's inside of z. | 2,745.18 | 1.65 |
So let's make Adder --
nice, no mistakes this time. | 2,746.83 | 3.26 |
Dot slash Adder, enter,
x is going to be 1. | 2,750.09 | 2.94 |
>> Y is going to be 2. | 2,753.03 | 2.35 |
And the sum of x and y is 3. | 2,755.38 | 3.584 |
So that's all fine and good. | 2,758.964 | 1.166 |
>> So you would imagine that math
should work in a program like this. | 2,760.13 | 3.13 |
But you know what? | 2,763.26 | 0.78 |
Is this variable, line
12, even necessary? | 2,764.04 | 2.864 |
You don't need to get in the habit
of just storing things in variables | 2,766.904 | 2.916 |
just because you can. | 2,769.82 | 1.16 |
And, in fact, it's generally
considered bad design | 2,770.98 | 2.57 |
if you are creating a variable, called
z in this case, storing something in it, | 2,773.55 | 4.55 |
and then immediately
using it, but never again. | 2,778.1 | 3.29 |
Why give something a name
like z if you're literally | 2,781.39 | 3.31 |
going to use that
thing only once, and so | 2,784.7 | 2.07 |
proximal to where you created
it in the first place, | 2,786.77 | 2.61 |
so close in terms of lines of code? | 2,789.38 | 1.672 |
So you know what? | 2,791.052 | 0.708 |
It turns out that C is pretty flexible. | 2,791.76 | 2.72 |
If I actually want to
plug-in values here, | 2,794.48 | 2.106 |
I don't need to declare a new variable. | 2,796.586 | 1.624 |
I could just plug-in x plus
y, because C understands | 2,798.21 | 3.47 |
arithmetic, and mathematical operators. | 2,801.68 | 1.71 |
>> So I can simply say, do this math,
x plus y, whatever those values are, | 2,803.39 | 3.75 |
plug the resulting
integer into that string. | 2,807.14 | 3.64 |
So this might be, though
only one line shorter, | 2,810.78 | 2.95 |
a better design, a better program,
because there's less code, therefore | 2,813.73 | 4.75 |
less for me to understand. | 2,818.48 | 1.441 |
And it's also just cleaner,
insofar as we're not | 2,819.921 | 1.999 |
introducing new words,
new symbols, like z, | 2,821.92 | 2.7 |
even though they don't really
serve much of a purpose. | 2,824.62 | 2.89 |
>> Unfortunately, math isn't
all that reliable sometimes. | 2,827.51 | 5.38 |
Let's go ahead and do this. | 2,832.89 | 2.38 |
I'm going to go ahead
now and do the following. | 2,835.27 | 2.93 |
>> Let's do printf, percent i, plus percent
i, shall be percent i, backslash n. | 2,838.2 | 9.45 |
And I'm going to do this-- xyx plus y. | 2,847.65 | 4.59 |
So I'm just going to rewrite
this slightly differently here. | 2,852.24 | 2.581 |
Let me just do a quick sanity check. | 2,854.821 | 1.499 |
Again, let's not get ahead of ourselves. | 2,856.32 | 1.666 |
Make adder, dot slash adder. | 2,857.986 | 3.434 |
x is 1, y is 2, 1 plus 2 is 3. | 2,861.42 | 3.53 |
So that's good. | 2,864.95 | 0.92 |
But let's complicate this now
a bit, and create a new file. | 2,865.87 | 3.19 |
>> I'm going to call this one,
say, ints, plural for integers. | 2,869.06 | 4.29 |
Let me start where I was a moment ago. | 2,873.35 | 2.63 |
But now let's do a few other lines. | 2,875.98 | 1.79 |
Let me go ahead and do the following,
printf, percent i, minus percent i, | 2,877.77 | 5.66 |
is percent i, comma x, comma yx minus y. | 2,883.43 | 5.529 |
So I'm doing slightly
different math there. | 2,888.959 | 1.791 |
Let's do another one. | 2,890.75 | 0.874 |
So percent i times percent
i is percent i, backslash n. | 2,891.624 | 4.986 |
Let's plug-in x, and y, and x times y. | 2,896.61 | 4.82 |
We'll use the asterisk on
your computer for times. | 2,901.43 | 3.1 |
>> You don't use x. x is
a variable name here. | 2,904.53 | 1.86 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.