Updates: Tyler on PowerHacking CSS to cutestrap your app in this latest episode!

Topic 14 - Conclusion and Wrap Up

Outline:

  • the preprocessor (include and define)
    • multi-file and multi-library
  • the main C function signature
  • reviewing the whole course
  • don’t reinvent the wheel - libraries and the linker

Transcript:

all right what's up everybody sorry we
had a few skype
issues but now if the skype gods are
with us
then we might have jessie hi everyone
yeah
we have jessie sweet sorry about that
that's all right
disastrous that's that's fine we just we
had to
sort out audio driver issues maybe maybe
now that we know c we can fix them
oh yeah well anything would be better
than
the windows kerfuffle yes it's very fun
to deal with
those kind of problems but anyway we're
not going to talk about machine
issues tonight we're going to wrap up c
as an additional language this is the
last and final course
in the caal series
so that's a lot of a's and um
i think was that did that count look
good to you jesse
yeah i think so you should just have
like an abbreviation like a3 or
something
ca3l yeah that's that's better i like
that
yeah we'll do that um so fancy
we had a nice little bit of fun on the
start screen that was
a uh this is just a little bit that i've
been playing with lately this is a
10 degree of freedom uh sensor which is
pretty fun inertial motion unit um so
we'll probably get to that later
but um instead today we're mainly going
to be
going over the series so this is uh kind
of
now we we're probably going to go on
with some project work after this but
today it's going to be a little bit
different than usual we're not going to
be doing
a ton of coding because we've mostly
been doing that so
we do have jessie here there she is and
we have our multi-user pad where we can
actually
like see all the wonderful things that
each of us is typing what we want to
compile
and if we're in luck then this actually
still runs yeah good okay we're getting
output
so yeah
i know that's the problem you know a few
tech issues it's like now we just gotta
go
okay reset we're good all right we're
gonna we're gonna go figure that out so
um i'm going to let's see jessie has the
white board up here she can take a look
so
let's show all of you now i have not
tried this out on this computer so we're
in
all sorts of experiment land for tonight
so i'm going to
inertially move this sensor and get it
out of our way
and the puns will be coming all night
don't worry
and uh all right so what did we do we
had 14 sessions do you believe it
oh my gosh are you serious i guess yeah
you've been keeping track so yeah
yeah this is topic 14. this is like
quite a journey i mean you know you you
made a
idle comment one day like
wanna learn c and
uh here we go we're there we're on that
journey so
um what did we do well that's actually
our recap so
um we had a lot of fun first we started
off now we assumed that we were sort of
starting from
a kind of python basis so we had some
programming stuff we weren't going over
basic
syntax we're just kind of skipping right
to the meat of the language um
and by the way can you see this is this
visible enough for you
hopefully oh yeah okay good um and chat
let me know if anything's like cutting
out or for audio is too low
or you know i think my audio disappears
randomly or if it audio disappears
randomly that would all be important
information
okay so where do we start well data
types okay so
we went over the c data types because it
actually has them
unlike what we do in python we actually
have to be really
strong about declaring them so unlike
python we've got to say exactly
what we're using and how much right
and what basic data types do we have in
the language that weren't really that
many
like we use a few and we sort of
construct more complicated data types
from them so
some of your favorites the original data
types that we dealt with
oh goodness uh care yeah care who cares
wonderful all of the various ends and we
learned signs and signs
unsigned yeah then we had
long and we had yes we we talked about
short but yeah it's kind of out of favor
these yeah short didn't really come up
too much
long did here and there oh oh short came
up short
oh boy okay what's up paul blart mold
cop
good to see you uh so um and
if we talked about the sizes of these we
learned that they were kind of
non-standard across
time and care bears there
nice nathaniel so
um yeah you can do a care and you can
make it a bear
i i don't know how to draw a bear
get my big nose okay that
bear bearish
um okay so anyway um we we had um
so we we knew that these types this was
sort of our basic one
and it was typically like eight bits and
our
our long was typically
32 but these days it's usually 64.
and then int was sort of really
non-standard and eventually kind of
aligned with long most of the time and
sometimes not and it really depends on
your architecture but um
these days again usually 64.
um so this was just our convenient
number size and then we learned about
the signed and unsigned versions of all
of these
and we actually got into a little bit of
detail about
how unsigned is stored in the computer
i remember uh rather deep lecture we we
are the beginning of tangents really and
we talked briefly do you remember how we
do
negative numbers uh on in computer
representation
so if there's there's a bit yes at the
very
well depending on which way you're
counting from at the very end
and it determines yeah it's the leftmost
bit
and that determines whether or not it's
negative yeah we had a sign bit um and
that's why unsigned like kind of gives
you
it how to put this so signed integers if
i remember correctly
you kind of have less space for the
positive because
you have to like you have you have to be
able to have that amount
negative as well because you're using
that bit for that but if you have an
unsigned integer you kind of can use
a lot more space for for the positive
numbers but then you have to
keep in mind obviously that it's
unsigned and you can't you don't have
you can't indicate a negative which is
pretty cool
and we did originally this was
just the signed bit and we did that um
sort of the old-fashioned way and that
led to an immediate problem because
what what what problem did this present
when we wrapped it around
oh this is this is a long time ago so
yeah this was this was
is this like the two's complement yes
that's exactly what it is so there was a
there was a twos we started two's
complementing and
this i'm not going to get into the
specifics of how it happens but
basically this dealt with our problem of
plus and minus zero oh right because of
zero the problem was
zero gets counted twice right yeah and
so you have to
we don't want to this is this is bad
right we
we don't want that and we also want to
make sure that our our typical
addition works you know so if we add a
negative to a positive
and this one's big and this one's small
then it ends up over here and if this
one's big it ends up over here and you
know
so on and so on so we wanted to preserve
that and we wanted to preserve gates so
we ended up doing this kind of crazy
two's compliment thing
okay um don't worry the test the final
exam does not include two's
complementing so that's
you'll be all right for that any
questions
on basic data types i don't think so
we've
used them so much that i've gotten a lot
of second nature now
yeah and i mean i told you about that um
that time that
i i was debugging something pretty
complicated for work in python
and just i i was very tired so i should
probably preface that
and i literally started to declare
in c fashion because i was you know i
never really understood what people
meant i guess by like
the the shifting types or the like
dynamic dynamic typing in python i
understood it conceptually but i never
really understood why being such a
problem
like to me it seems like such
flexibility and then i got into this
very complex
um problem and when you're digging
through thousands of lines of code
you need to be able to figure out what
type things are and i
missed that declarative c fashion of
being able to know immediately that
this variable is this type and it's
going to stay that tight you gave that
up for the flexibility no
i know the flexibility is nice but yeah
i was so tired i started writing c
uh so we just we have uh we have a guest
here uh uh
math thank you for showing up came back
one of the
new subscribers who gets the cool
e-boats and everything else
um use and celadosaurus use my pie
interesting a little bit of advice there
from nathaniel
so all right these were sort of the
classic data types and then
of course you know i i got something
handed to me by uh last miles who was
very very upset in my initial stream
um because he thought i wasn't gonna go
into the
the new types what were the new types
then we we sort of
shook all those like classic types which
were sort of like
standards mess off and then we got to
our nice new standard types of what
what do they look like ah is that like
the u
and c
and then there's a 32 t and you know we
can have a uint
and a 64 t and then we can actually just
drop the u and you know just have it in
64 t
and all this other so anyway these these
types were really nice because they're
super portable they're far more portable
than these other types
which are a little bit more machine
dependent so this was kind of like the
machine independent
data types and that was
so we try to use that as much as
possible but
obviously with original code we're going
to run into the the
classic types okay and if you're paul
blart the mold cop and you're
running in javascript you can just
declare everything as var and you know
call it a day
even though that's not even cool in
javascript anymore because they moved on
to like const and let
all that other nonsense but anyway so
we're not talking about javascript here
we're
we're we're no we're in c okay
so where do we go from there well we we
finished up our data types
and we were just sort of cruising along
yeah paul farts not into the new age
stuff yeah
i mean that's so the see new age stuff
would be those new portable types
but okay and we got into representative
questions yeah
so prior to those portable types
when typing was insane it depended on it
was a dark
time okay i was just like
would you have to have some kind of
system check to figure out
that's actually how those portable types
work they they use
systems checks and they sort of do it
for you so that way it's not
littered all over your code and you can
just kind of be clear about i want 32
bits i want 64 bits
you deal with finding the type for this
compiler in this system
okay um so from there you know we
quickly so i just
quickly touched on representations um
and that got it a little bit into
bit pattern so we we talked very briefly
about that with two's complement for
negative
and we also know that when we're on the
system
uh we we're storing things in binary and
we showed the classic example of
eight bits uh so our maximum value is
255 and our
minimum value was zero and
we could get there by basically doing
powers of two
sort of the same way we would did with
base ten right so
in this case this was this is the two to
the zeroth place
and that was a terrible drawing so that
was two to the zero
two to the one two to the two two to the
three
to the fourth and so on so um
on up to the two to the seventh bit and
if i set all of these bits to 1
i get my maximum value which happens to
be 255.
and these roll over as soon as they hit
the number 2 because if i put a 2 in
here
no it's too big so this becomes 0 and it
rolls over and that rollover math
works the same as it does with base 10
numbers so if i'm doing a 10
that's all fine but if i go and do a 19
and i add 1 to it i got to roll over to
the next digit so this becomes a 20.
all right so we understand
this it works the same way in binary as
it does in our classic decimal
and we learned a handy notation for
quickly referring to this which was
hexadecimal which would refer to four of
these at a time
so f here being all ones
and zero let's see well this was also an
f so this was all ones so i could write
this out with two letters which is a lot
simpler than writing all these bits out
especially when i start getting to
something that's like 32 bits or 64 bits
or something like that
so all right any questions on
representation
i don't think so okay well we don't
yeah that's i'm feeling good too we went
through a lot of representation so
from representation we moved on to
uh looping and looping
is a bit different than python
um we had three looper operators so do
you remember what they are
for if and while so not if
not if no if is a conditional so that's
just if
something oh i guess yeah that's not a
loop so there was one
these two are the ones that we focused
almost all our times on
uh like oh hold on hold on it's four no
there's one it's two letters yeah
there's two it's a screwy version of
this
there's like a y which i told you never
to use and i'm happy you don't even
remember it because just purge that from
your memory
but it is the do while loop do while
that's it okay
all right don't don't i never don't
don't do it don't
i forgot it do while it just just while
and four and we learned sort of like
when these would apply like we used four
when we were doing sort of counting
kinds of things or
you know iterating kinds of things and
we used while when we were doing some
sort of like
boolean condition like you know like
reading a file for example so just keep
reading this until you hit the end of
the file
um so and we could always use a for as a
while we could always use a while as a
four
we could be as mean as we want all the
other programmers that have to manage
our code base later but
we try to follow conventions and be good
about when we use each one
okay so we did learn
that scope is local so
four was a little bit different from
your python four
right which was kind of a for like x in
y
sort of or whatever that said for
x in y kind of
python but we're not in python we're
doing c and we only have one type of for
loop really that we care about
and it was what does it look like
so you have three statements um
separated by
semicolons and the first one is your
starting condition or you're starting
i guess not condition because it's just
your starting value i guess
um and then there is
kind of uh it's your why like i always
abbreviated it as my while condition
yes so it's the condition that the loop
will keep on looping
as long as that condition is met and
then there's your
how you want to iterate whether you want
to do it at the beginning of the loop or
at the end of the loop yeah that's sort
of what you do
at each loop right so yeah add one to it
or whatever take the next element
whatever whatever that happens to be so
this is sort of your i like to call it
the iterand
but i don't i don't think that that's a
word
so don't don't don't call that that uh
nathaniel probably knows if that
actually is a word or not
but um so okay we can do this and you
came to really like this even though i
told you that the whole design of python
was to not do this
i know which makes me so sad sometimes
now when i'm doing like
python loops and i want again i like
crave that
extremely explicit nature because
especially when you're trying to debug
something that's really complicated
it's a blessing to have everything so
explicitly stated also
exactly why they did they they were
fighting one
exact problem with this which is
extremely common which do you remember
what it was
we didn't talk too much about python
language design but i can tell you right
now that
i'll we touched on it very briefly but
the main thing that they wanted to get
rid of
is off by one errors okay
right and that's something that i ran
into we all do it
we all do it this is super easy to do
because you're managing the iterand
you're managing the star
you're managing the condition so it's
very easy it's like do i
want to be like equal to or greater than
is the
plus happening before or after the loop
have you know like there's all these
like kind of like things that you've
probably
you might get wrong and if you slip
you're one off and it's just a super
common problem so basically the whole
design of this was
don't let you do that like so
so that's by design including myself so
because people we're kind of too stupid
to stop doing that
they decided to take away the fun tool
and give you one that kind of restricts
you a little bit more
yep yeah that's basically what happened
um so that is
that's a good thing and i don't know why
skype wants to be difficult with me
but what's going on okay you can still
still here we're all good
um okay yeah and we've been having fun
okay so um all right so we know what
we're doing with loops that's cool
there other than that other than like
sort of how you set them up and you know
which of these you use and the fact that
there's this three-part syntax
they work pretty much the same as what
you were used to in python
okay and you do have a while there as
well and you don't have a do while
instantly
because they know that that was crazy
okay um
so anyway uh great from there we moved
on to functions
and functions were a little different
than python
in particular we had to be really
careful about memory
and we had to be really careful about
what showed up
to the function to its own scope this is
something we didn't deal with a ton in
python it exists
but uh it's not as kind of strict
because everything's sort of like a
pointer
without the pointer syntax so modifying
stuff happens only in the scope of the
function and that's where we got into
stack frames
and so we drew lots of diagrams of what
memory looked like with lots of lines
and we said
okay this is the stack frame for
function one
and all right let's call this two and
this is function 1
and whatever um actually in this case
i'd have my stack growing up which is
bad so this would be function 1 and this
would be function 2.
we want we want our stacks to grow big
engine and
something yeah which gets into a whole
processor fight but
anyway so um and we can kind of like you
know say that these are stack frames and
so if i modify a variable in here
and then we talked about different
calling conventions briefly um
so when it's kind of cleaning the stack
up whether it's the caller or the
callee's responsibility say funk one
called call
funk two in some language platforms funk
two is responsible for cleaning up and
some funk one was responsible for
cleaning up
it's a set of conventions and um what we
had to worry about was if we overflowed
this stack
which is actually where we get the term
stack overflow
when we when we sort of reach out of our
frame and modify something you know
that could potentially be bad so um
we'll get into
stack smashing and whatever and sort of
more advanced
smashing okay yeah stack smashing it
sort of sounds exciting security do i
get a hammer
um yeah yeah it's called a compiler um
but
it's it's a powerful hammer okay so uh
this this this is sort of like we had to
be careful about what we passed forward
and back
um we only can return one thing
and that meant that whenever we had our
return
either we had to jam all of our stuff in
there sort of like
a dictionary you know and this would be
in c this would be a struct
so i either had to jam everything in
there to return
or i had to mess around with pointers
and i had to be careful with pointers
that i declared locally because if i
declared a pointer
here and i return it back here
this is gone when this stack frame gets
cleaned up so
this is where we messed around a little
bit with global reaching outside of the
stack frame
and this is also where we messed around
with having funk declare a pointer and
pass it in
because then we can sort of modify it
back um so we had a few cases of that
that you know again that's probably
something i need to
drill the heck out of you in a future
class but
probably but yeah reaching in reaching
outside of your stack frame is
you know there's techniques for doing it
but you have to be careful
okay so we we we had a few little bits
of fun with that
any questions on functions
i don't think so okay well
that's good because i'm going to test
you later no i'm just going to oh no
okay we're just doing a review okay then
after that
we got into stdio which was our standard
io library
and there used to be a non-standard io
library all these different platforms
had
we didn't worry about that we're using
the newfangled see newfangled as of like
the 70s
[Laughter]
so this would be that new agency that
sort of came around and
and
we learned a um we had sort of two
sets of functions we worked with we
broke this into two sessions there was
there was kind of the character
and let's say string oriented stuff
and then there was the kind of file
oriented stuff and we worried a little
bit
about both of these in separate sessions
but you know with with these character
things we had stuff like
how to copy you know so we learned about
str copy
and we learned about str len you know to
get the length we actually implemented
this ourselves
because we had to learn about how
strings were constructed which
ended up being if i wanted the string
jesse to be in memory what did i have to
do in c
it's an array it's an array of
characters
and what was special about it um that
technically
if i were to refer to it it's a pointer
to the location of the first character
that's true so there's my care pointer
and or i could just say that this whole
thing is an array
but there was another special property
we had to worry about
um i'll give you a hint
oh because so it was another kind of
like off by one error yeah you have to
remember
that there's um the null byte at the end
and so when specifying enough memory for
your string array
you have to remember that in terms of of
memory super important
so and that's actually how we
implemented these different functions
was
we could sort of scan through the string
until we hit the null byte and then we
knew
we were done so if we had a string that
wasn't
null terminated we could really get
ourselves into a lot of trouble
so because this would just sort of keep
running through memory forever until it
crashes
if we get lucky okay so we implemented a
few of those
then we moved over to the file stuff do
you remember some of those calls
yeah it's like f get s f g
um this is where we introduce i guess
it's it's not a
how do we get an f first type but
it's it's like yeah i think it it's a
data type
five yeah um and so how do we start with
one
how do we start with one oh we need um
no the first thing we need to do to get
going with
file stuff is there a libra or like an
include that we need oh well yeah i mean
it's stdi
well you have to say like we used
f-a-f-h i think for file but like
yeah yeah and what do we have to do with
fh
well you have to declare it yeah you
declare it so it's a file pointer
and then what do we do with it
immediately
uh close it well yes we close it but
before we close it what do we do
open open and close yes but you
you definitely were on my case out
always closing it though yes
it's great that you remembered close
before open that makes me very happy
um so here we would just specify our
file name and then we would have our
our specifier for whatever permissions
we wanted
this could be and it was the same pretty
much as what you saw
in in python because they took it
there's
all these different there's appending
there's reading there's writing
there's all this stuff yeah those were
absolutely
the same from python yeah python didn't
invent something totally new i mean they
just
that makes sense so we're going to do
that um so
more specific this is actually called
posix file semantics
okay um but i i i feel free to tell you
that
now because now you know how to use them
so
that's might as well give you the
terminology okay so
um files were kind of fun that was we
mostly started off with these read write
and append and we were dealing with
character strings which we knew how to
deal with
until we got to what
um until we got to what was the other
way that we could deal with files that
was not binary
yeah exactly so all of these had binary
versions of them
read binary write binary append binary
and these we did not use the same
f get s and f put s type operations
we also had an f print f and you know
there's oh f printf yep
yeah there's there's actually an f scan
f anyway so
like we don't have to worry about all
that stuff but um this
when we got to the binary world we could
not use these so
what were we using when we got to the
binary world
i only had two operations oh
i am not remembering um a while ago
that's why we're doing a roommate
shaking the cobwebs out um
i think if i could promise you a review
so
um okay how do we
so well it's not a huge mystery i'm
going to tell you that
there's only really two operations you
can do to a file anyway
i mean it's referred to you can read and
write i o right yeah it's
read and write so that's it so
there was f read and f right
oh yeah okay and they
basically unlike this other stuff
which we were dealing with where we
could sort of assume that there were
string semantics
these did not and what do we have to do
to deal with that
um so
[Music]
is this no because that was i think we
had no no i think it was f read and
upright where we have to specify
the unit of memory and then how many
units we want to read
right yep so you have to be very
explicit about how much
how much you want to read and what the
units are
um we had to say how much we had to say
what the unit was
we said where and we said what else did
we
i mean we said which file to work on and
then we needed one more thing in general
which was hmm okay so i'm remembering
hold on because i remember the
well so your file handle goes last yeah
and then
there was oh this no yeah because there
was let me say so
i could just see it in my head for a
second yeah
right the and then what was first right
because yeah the second thing
the second thing was the what was first
the size of a unit
the third thing was the number of units
the fourth thing was it was a pointer
yeah it was a pointer for what
um it was actually the introduction of a
new type for us
oh no i'm drawing a blank
the first time we saw the void pointer
the void pointer
which was said this was just a block of
memory
this we usually refer to this as a
buffer of some sort
and this was strange
because void was basic at that time you
you yelled at me
because you said no void is what you put
in a function to say that there's no
parameters there
and i said that's that's true that's
true
well turns out freud has one more use
and that's when we need to say that
there's memory but we're not saying
anything about its semantics and that
was super important so whenever we're
doing void pointer type operations
we're intentionally not seeing what type
of memory this is i still some i still
i'll be honest i still struggle with
that a little
a little bit and like i i joke or like
earlier saying it's like a cthulhu
pointer but it feels very sort of like
nebulous and lovecraftian and dark magic
and like
it does use the word void so summons
summons ancient evil
it comes from yeah it comes from the boy
so i mean it's part the name part just
it makes me a little uncomfortable just
because i think
part of what i liked so much about
pointers and also about how explicit c
is is that you always have to know
kind of what how much how much memory
you're going to be using or how much
memory you're going to be pointing at so
void pointers seem to just kind of be
like nah now we're breaking the rules
yeah and so that i guess i'm still sort
of mentally struggling with
um ah but what other thing could we
specify for the buffer
i mean anything else we pick imposes
semantics on our read and write function
yeah so we didn't really have a choice
right
so why do you need a void pointer there
though
because we're not saying what type this
needs to be
but we are being explicit still about
the memory because we're specifying the
unit of memory
yeah and then right yeah okay all right
so it's just that we don't want to put a
name we're passing along the semantics
we're basically saying we're going to
tell you how much and you know how long
and whatever but
we're not telling you what it is it's
it's an
obscure detail it's opaque so basically
turning a void still is weird
well it's just not giving you any rules
i mean it's just basically saying that's
that's like come on c is all about
liking rules well i mean if we wanted to
add semantics to it we had to actually
do what
which we actually did because we wanted
to what like when we got our void
pointer out we couldn't just use the
void pointer we had to do something to
it
what when we got our void pointer out
yeah it's slow all right we can't just
operate on the void pointer directly i
mean we
no no you like are you talking about the
and operator so you get whatever it's
pointing at
yeah well we could de-reference it the
star operator but
um no the um what i'm talking about is
that we actually had to take this and
move it into a different data
type so we had to give it semantics
casting exactly so as soon as we learned
about this we also learned about the
cast
and this was really important because we
need to be able to say okay this is
actually
character data or this is really int
data
or this is some arbitrary structure data
is that what's going on under the hood
with python's uh
dynamic types is it's just a lot of
casting kind of it's just
a little bit more complicated
but yes like that is in general sort of
the idea
okay or you can just de-reference the
void pointer straight into the void as
the ronin says okay so we learned a lot
actually which was just sort of on the
side when we got to binary
files and there was something else about
them that you really didn't like
oh no and you got you got angry at me
about it no okay i was telling you like
okay you can just read and write
and you just read and write however you
want to these things
um and then low phone came in your room
hi oh thank you it's dinner i'm sorry
oh okay oh just don't touch her cable
because she
don't touch it the world will end
the world will end okay
all right so i got angry at you about f
reading f right
yep because
i don't remember they did not
specify the format of the file
oh right so like file
um extensions you just don't use them
well you do use them you make them up
this is actually how they're made up
you decide on your own set of
conventions the
the data is not necessarily
self-describing
so that was kind of the important
takeaway and that made you
kind of ticked it just seems like
i i get that if you think about it
it's like you have to specify it so yes
it's very c like but at first it seemed
very unsee like because c is so like you
have to specify
all the things you have to be explicit
about every little detail and so it
surprised me that that wasn't
yeah i mean we said that you could go
into different formats that were
self-describing and
a lot of formats were not
self-describing okay
so from there we moved on because that
led us very naturally into
structs and when we got to a struct a
struct was what
it's kind of like um it's kind of like a
dictionary kind of like an object
a little bit i guess um
but it's it's kind of
a way of
storing and organizing related data
yeah okay i like that that's a good way
of putting it organizing
related data and how do we build one up
struct yeah
you declare it yeah we declare what our
structure type is
you know so it could be like a planet
was the example that we did
yeah we used planets and then we said
that this has what in it
um so we i think we used uh like orbital
period
and radius
mass name name okay
and we just we we went simple we kept it
fixed size so we said like okay name is
like 20
and orbital period and this was like a
float and this was
like a character well i mean it's just
an array
and then that was the definition of our
structure
and then we knew that when we declared
something we could say
struct planet
bob
how do we assign to the different parts
of it um the
dot or period operator
so oh like bob dot name
equals bob oh wait can you assign that
to a
carol uh how do we do that
[Music]
we um by with a little help from our
standard io
did we did we just used like the the
brackets with
i mean the first one we did we could do
it one at a time we could do a character
at a time and say
yeah i remember doing that but i
remember there being like some fancy
other
easier way to do it oh yeah that was
definitely a fancy other easier way to
do it but
because doing this is a lot of writing
and it's
pretty annoying and you know this is
okay and this
even if i pick the shortest planet
there's a lot of a lot of work that's
still a pain
yeah okay so we use the str copy
oh okay and we just specified that
bob.name was going to get
like mars and we had to be careful
that we remembered that this had that
and we learned something else about
strucks which is that they sometimes get
padded
and this occasionally screwed us up when
we started talking about
writing files so i'm thinking about how
much memory we would need
yeah we had to be careful about
something like padding because padding
like
would make the cpu faster but it also
would burn by there was a way to specify
like to get rid of the like to make sure
that there wasn't padding i don't
remember the exact syntax but did you
remember that we could do that yeah
there's attributes
anyway we're not i'm not looking for
that level of specificity don't worry
you can you can look that up if you need
to okay but it was important when we
were talking about serial
serializing data and storing it
somewhere okay so
from there we moved on and we
uh we also sometimes had to deal with
um a pointer to one of these things
and that would be something like
uh you know current planet
oops planet and
when we were doing this we could say we
had to we had to do
a reference because we needed the
address to be able to put it into a
pointer so
we would say this gets and bob
and that would assign it up and then
when we wanted to access it with the
pointer how did we do that um
so there's two ways but i like the pew
pew operation use the qp
operator yeah okay so we like the pew
pew operator so we're using the p
view operator so we could go if we want
to get the orbital period we could do
kerr planet what um
and then let's see you use let me see if
i can remember how to do this
um use the ppu operator and then
um like
so and and bob so bob dot name or
something
well i mean you have bob so like yeah
you you could take name
because our name is already pointing to
bob right
okay and we had the reverse that we
didn't really do this with structs but
we knew that if we needed to dereference
a pointer and like get the thing that it
pointed to
we could do something like this
it would throw a star in front of it
okay so we we had a gentle
gentle introduction to pointers at that
point
and it um they weren't as bad as they
seemed until we got to the next topic
which was dynamic memory
something you just take for granted in
python and that's actually part of why
it's so wonderful
so what happened when we went to dynamic
memory
we had two operators that we had to deal
with
uh is this malloc yeah kellogg yeah
chunk alloc don't worry about kellogg
kellock is in there it's sort of like a
ray
mallock um but when we malloc something
what do we have to do to it
oh free yeah that's
focus on these two don't worry about
that one because you could always just
multiply this
out and get the same thing okay but yeah
this is important and then what we did
was we basically
dealt with this um in the first session
we actually did the dynamic memory
allocations using matlock and free
and then because we really wanted to hit
the concept home
we did the challenge that's our team
chalk
and this was about this was the session
on bring your own
allocator and we built an allocator that
never gave back memory so we made free
and no op
and we made free free and we just said
malloc is going to be chunk alloc and
we just kept on dishing out memory and
this is where we started using the void
pointer for real
because now we don't know the semantics
of the memory
that's kind of up to the programmer okay
so
that was kind of complicated and of
course when we did all this we hit our
first
memory leak i remember that and i was so
proud
but uh something you can't actually do
in python it's not
really the language doesn't permit it
but you know it's c
c absolutely does and we leaked memory
like a champ and there was no warning
and no nothing and so
what we could do is go back and build a
better version of chunk alloc
that could track memory allocations and
deallocations
so there's not you just have to do the
bookkeeping
there's there isn't really another way
to do it there's tools that will help
you with that
i mentioned one briefly which is called
val grind it's a great tool
uh there's there's other ways to do this
but we do this is sort of advanced
stuff it's not really part of the
language okay
we we could do it our on our own when we
were building our own allocator and some
allocators actually
give you those options uh to work with
so and there we took on the
scariest topic and see because
everything's easy after that right
i don't what's the scary stop i can see
i mean memory allocation
oh but see i it's it's just under this
beautiful haze of chonk
so it's a positive wonderful memory for
me because there you go
it's all about trunk well that that jump
brought us to
the last major part of the language
which was
bitwise operators
oh right okay that's more fresh in my
memory and well now we're back into
recent history
so bitwise operators um what do these do
so these are a series i would say like
logical operators kind of um that
operate
on a bit by bit level instead of a
decimal
addition subtraction or whatever exactly
and they were the same as the
uh sort of conditional versions of them
in the sense that there was an and there
was an or
there was a knot there was a um
xo and there was an xor yeah which was
the exclusive version of that
um and and this just basically did it on
a bit by bit basis so if you had two bit
patterns in memory
you could piece by piece do these
logical operators and determine their
result and we could do truth tables and
we
started doing that hashes were in there
too somewhere before bit wise
i'm sorry okay i'm getting really
excited i know i know i know we're
almost there
i thought that happened before so you
have no sense of time that's okay
and then we you know we could do
whatever operator and spell it out
so um that was fun that also brought in
a related topic which was bit
shifting so we had right oh this was
weird
this is this felt uncomfortable it made
sense but it was weird we could we could
take all the bits and we could just
tell them to slide
right it's kind of how ccds work i
remember thinking that
and there there there there
there there all right so we could shift
right we could shift left
and all sorts of other fun stuff okay
so questions on bitwise
we just did that so actually that's
really fresh in mind that's super fresh
and it was really handy for the next
topic which was
we began i know you want to get excited
but don't get too excited because
first i'll get myself under control
first we had to go through one
intermediate step which was
the final section which was the missing
parts
and here we were we broke this into
three sub units
and the missing parts was really about
stuff that isn't directly the language
but sort of like
hard to get behind the language without
it so
and i'm gonna ask about that song in a
second but
um so the missing parts i broke into
three categories we had hashes
we had sorts right and
we had random numbers
let's just call this this section
entropy
in general because we got into both
pseudo random number generation and we
got into
true random number generation the really
true sense of entropy
okay so um
hashes we
we did a few right well what was our
first hash
oh what was our first hash we actually
used the length of the word
oh that's right yeah it wasn't a very
good hash
so um so
we have things like word length we have
things like
you know we could add all the numbers up
we could
add them up and stir it a little bit
by the way you'll notice i'm borrowing
the word stir from entropy because these
are all related fields
um so we could be a stirrer and then we
actually quickly did djb
which is a really dj b2 which is a very
useful hash but not something you're
expected to memorize it was basically
just
kind of a couple shifts and a few
logical operators and some prime numbers
in there
all right and we never explained why
sorts
we did a couple sorts you implemented on
stream you remember them
oh not the cute one we didn't do that we
did
not do the keyboard we used the q1
there was like the oh this is the one
you're like
in an interview so similar i'm going to
call it
the line of interview
and make sure that cue sort is always on
the other side of the line
do not cross the line if you don't have
to so
the two that i said that if you ever
under the gun you should never use them
in real production code but
they're not too bad to implement and you
actually you nailed both of them
i swear like one was like a reference
sort and one was like an assigning store
insert insert yeah that's one
insertion and
they had such similar names and i
remember getting them selection thank
you
okay and they were both sort of variants
of kind of the same idea uh
so we implemented them from scratch
that's this is kind of
by the way this is sort of one of the
topics of you know the more advanced
course
so this is after we get into data
structures we really start getting into
hashing and sorting
um but and that's really kind of the
general topic of computer science but
the last one
was also equally probably more important
these days
especially with security and that was
entropy and we talked about two types of
entropy
do you remember them oh physics brain is
taking over i'm sorry computer science
enterprise um
well let's talk about random numbers
then oh well we we talked about
pseudorandom numbers and then actual
random numbers so there were pseudo
random numbers and there were true
random number
generators and actually this isn't
really a generator this is kind of a
misnomer because
you don't generate it really generates
yeah you harvest measure it
yeah and we can we can go harvesting
true random numbers you know
going we'll get into entropy a little
bit more after this but um
so with pseudo random number generator
what was our goal
there was a bunch of standards and we
didn't have to worry too much about
the direct standard um but we weren't
gonna
we were worried about what they were
sort of testing for in the standard and
we didn't want it to be easy and we
didn't want it to be
um actually that's really all of it is
not easy and we broke down
we don't want it to be like back like
yeah to be able to like backwards yeah
we don't want backwards and we don't
want forwards
like we don't want it to be predictable
yes that was it predictable
and we don't want to be able to recover
it
right you know yes we don't want to be
obvious yeah we don't want to be
recurrent so
um and we also want to sort of hide the
state
um for where we did it and so that's
where hashing came in
so we could we could use hashing yeah
and then we would also hide our seed and
you know whatever else we wanted
okay but that was i got to be the most
troll like
that i've been so far that was really
fun yeah
super fun uh true random numbers where
did we find them
um so that's a that's like it has to be
a
phenomenon that you kind of observe yeah
it's usually something physical
and that's really important because
pseudo-random a computer is a very
ordered device
it's always trying to reproduce exactly
the same results for the same input so
this isn't there's like that entropy or
true random
number generator yeah like you said like
the nsa uses or something and it's in
your computer and you should never use
it
yeah that's the rd rand instructor there
we go yeah i forgot exactly what it was
so we actually was like yeah we busted
to some in-line assembly for that one
but
um there was actually a much better
place where you could get randomness
from and that was about collecting all
the environmental noise
sort of on a machine and i don't know if
you remember or not but this was the dev
random device yes
and we actually read a few bytes from it
we could just use
normal binary operators on it we could
just open it up and
kind of get to work and we were good to
go
so that's a lot of stuff
yeah okay yeah we actually as paul blart
just mentioned our
first random generator was the randall
monroe and we
checked how to spell randall monroe's
name
but there was the randall monroe number
generator which was just
returned four four yeah
okay so that's where we started we
actually started right there so
that in a nutshell
is c
how do you feel about that i mean there
was basically
that was all of it that's that that was
the entire language
i left one or two obscure details out um
they're not
super important other than the other one
that we're going to talk about today
which is actually the last little bit of
new content
and it's really just a teaser because
we're not really going to get into it
so say what i said in an interview i had
a job interview today and
i basically said that
i'm i'm i've i've learned a lot of c but
i would not call myself
a seed developer in any sense like i
feel like go ahead do some seed
development you got the console right
there
hello lord no no no no no so
i was like because they were asking me
about what languages i
i'm familiar with and what i feel
comfortable doing and
uh i was yeah i'm i'm learning c but you
know
i would ask me to write any i would say
that the biggest thing that you're
missing in c
is just practice it's not there actually
isn't
any more c other than there's some
technique you'll pick up
but there's nothing else in the language
it's really at this point it's really
about making everything that i just
talked about has to be second nature
um and that really comes from like doing
assignments and i never
had this that i i take the blame for
that
yeah you didn't have any homework and
and that's actually kind of like
the part that would really internalize
it for you like like that's
that i think is the biggest missing
piece from this class but
um that if if this tool was in a state
where i felt comfortable leaving it
online then we would be good but
it's it still has the warning glaring
security hole on the website
okay so that actually if we look at
our learn um that was actually that's
the whole class
so we we we did all of it we had some
data to play with
but you know that was i actually
developed a vocabulary we didn't use
so i have a thousand word astronomy
vocabulary that i'll probably just post
on the website but
um that's a that's a whole separate
thing uh
so anyway i mean aside from
practice which you pointed at right so
obviously like
you need some practice and see i think
yeah you can't just do it once and
say you
um that is is were there any like parts
the language that i mean
we didn't get into function pointers too
much um
we did actually use conceptually well no
we actually used one
in q sort so with q sort we actually had
to specify a function that it would call
to compare two
we didn't build q sort though we didn't
build it but we used it
um okay so that actually
does have a function pointer in it but
we didn't spend much time with it i mean
that's that's just kind of like you can
pass a reference to a function in and
say
have fun so
uh radioactive materials by the way
math those are a nice source um
cosmic dusts you know there's
everything related i honestly think
would be a great
it's fantastic source um well i got
infinite amounts of that
so yeah things that you can hook up to a
analog digital conv converter are
usually pretty good so like
i mentioned a detuned fm radio um hey
what's up gene
uh so there's there's all sorts yeah
twitch chat
alone is probably a fantastic source to
harvest
so we've got we've got all the
randomness we need right here
so um this uh so
that was that was kind of like in a
nutshell that those those are the major
topics to see so do you have any
questions about any of those
not off the top of my head which is fine
because usually i just
peppered you with questions more that
way too i mean so
if it comes up feel free to continue
peppering so
um anyway uh there's so for the last
piece there's something that we've been
using all along and we never got to talk
about
and i think that that's a good spot to
end our language study for
the intro course um and again
intro in the you already know another
programming language i think this is
totally inappropriate it's like a first
time programming course
um so the first
piece was this and i never really
explained it
um we just started using include and we
didn't really talk about what it meant
um it was a reference to like if we
include something
then some more functionality came in
and so we included things like stdio and
we got stuff when we included it we got
things like str
copy and str i thought of it like a
python library
yeah that's probably okay that's okay it
sort of is
um and we also when we included standard
in we got stuff like u and
a t and all that other things um there's
more here
right we can include math
um anyway so no we we you could include
all of math
um we couldn't because that's not dot h
uh
h means header so includes are almost
always dot h
okay that changes when you get to c plus
plus but for c it's almost always dot h
okay and so we can include and this was
kind of we we
learned it as sort of a way of bringing
in functionality i
kind of lied a little bit that's
that's not the whole truth so we we did
touch on it
briefly when we looked at the heap when
we actually did the exercise where we
looked at heap allocations and we were
like you know
okay kind of looking at uh self uh proc
self
maps um but there was a
i told you there was a sort of like
there was sort of the stack growing down
and there was the heap growing up and in
the middle there was sort of this like
area you should never cross yes
and that was that was important right
one does not go to mordor okay so like
like that
that little middle area across the
stream yeah don't cross the streams
this was our library load so this was
our shared library stuff
and that's actually this stuff the h
files
really just bring in the definitions
of what functions are in there but
they're not the functions themselves
so we didn't actually kind of do that
but like so for example when we when we
built the function like
so they just pointers to the functions
or well
sorta um so they're actually just the
definition of the function
so if i say something like uint
32t randall munro
monroe random
and this took nothing in and it returned
like four okay this is a full function
and this is the way that we
typically specified functions when yeah
when we were programming
well it turns out that you don't need
that
if it's from another file so okay
or actually what you can just like
normal i mean
what you really need on it all in one
file
yes but what you really need
is how this works this part that i
selected
c needs that to be able to kind of say
like what this functions
how to how to link it up how the stack's
going to work and everything else but
it doesn't really need to know how it
works until you're actually linking the
final executable and i know i'm hand
waving on link but
like if i have different like chunks or
chunks
of code and i want to sort of like link
them all together like i could
you know maybe different programmers are
working on different things or
somebody's building a math library
or somebody's building say
the fastest fourier transform in the
west which is
a real thing um and it is really fast
um so someone comes along and does it
like that you don't really need to know
the implementation details to be able to
call it
all you need to know is how to call it
and that's what we call the definition
so you don't need the implementation
which by the way is incredibly magical
this is the
implementation part down here it's very
very complicated function i picked
but we actually all you need to do to be
able to call this thing
is you just need the definition of it
and that's actually the definition
which is to say that this takes no
parameters in and it returns a u u n 32
t
okay so c only needs this
when it's compiling it needs this sort
of when it's linking
so okay
what that sounds like to me is that
it needs to know like from a memory
perspective
when you're let's see when you're
compiling
all you need to know is what it's going
to return and what it's going to take
yep and then when you're linking you
need to know
all of the other possible variables and
whatnot that you're going to
need the actual
yeah right so like in the first one
you're sort of saying
what it takes and what it returns and in
the other one you're saying this is
actually how to do it this is what to
run on the computer
so those two can be separated right so
this is actually
the definition where i'm just specifying
this is how to call this function
but here i'm actually giving you the
concrete implementation as well
so that's kind of the difference right
there
so this is this is sort of like the
protocol
i'm overloading the use of the word
protocol this is sort of like this is
how you greet this function
this is how it gives you back a response
but you don't actually know how this
thing works
just looking at the definition right if
i don't show you the function
this is actually enough to compile
what i mean i understand based on the
definitions you've given me yes but that
just
no i mean that's it i mean i can just
from this i can say all right take a u
in 32t and call uh you know call this
uh some number and then assign that a
randall monroe
random number that's enough for c to
be able to build this unit like it knows
that it's going to
eventually need to find this function
but
it knows already how that function looks
in terms of like calling it
that's it that's actually the difference
so this is
just enough information to be able to
call it but it's not enough
information to be able to execute it
okay
so is the the hashtag include thing is
that just somehow shorthand for
this is what you've highlighted there
but for all of the header files are
usually
just definitions so it's just the
definition of all the functions that are
going to be in there but
not the details of how to do it how does
it know
how to get the details of uh that this
is not really c
so this is kind of more of like build
systems and linkers and stuff like that
like this
this this gets kind of out of the it's
clearly related to the realm of c but
it's not actually the c
language itself so the important thing
to take away is that
you can split up the implementation
from the definition of it okay and this
is basically how to do it
so these header files
that's the part i wasn't entirely honest
about these header files
they have mostly definitions
okay okay how does pound include work
well it actually is a lot dumber than
you think
it's nothing like the python import
import
implies in the name that it actually
does some stuff
right you know like it imports this yeah
module right you know like it's bringing
it into existence and it's initializing
it and doing other wondrous things that
we don't need to know about
but include actually literally
means paste this text file right here
i was wondering okay take this text file
and paste it right here and that's it
that's actually how this is this was the
first
preprocessor directive so this means
before you go
compiling this thing first find this
file
and just paste it right here where do
you paste it exactly where it is on this
line so paste fftw
right here paste math.h right here paste
standard in
right here placed if i reverse the
orders these are not the same
this is a different program because this
actually
paste stdio right here after standard
and by the way that will sometimes cause
your code to break because sometimes
these things depend on
different yeah so you actually have to
be really careful that it is
really dumb it just copies and paste
that's it
it does no thinking like this this whole
import thing
this is a much more glorious term right
you know it's sort of
it's like i might initialize something i
might run something i might uh
contact a developer or i might run a
neural network while you don't know
i mean like this could do basically
anything you want it could capture
variables it could do whatever
this thing is literal it does not do
anything other than it pulls that file
in
and slaps it right there in the text
okay
and nathaniel is absolutely right this
is it it's kind of beautiful and how
simple it was and it's also terrible and
how simple it was because that actually
caused
all sorts of trouble that we learned
about later but you know so that was
kind of like
that's the beginning of the preprocessor
there's one like every
every code i've ever written super
important with c
c such an early language so like a lot
of development we were sort of learning
like what bad ideas were
that's and there's a lot of opinions
those opinions are now called
programming languages because those
those opinions have been followed for a
long time
okay so there's one other pre-processor
directive we're not going to get too
into but it's called define that okay
when i was
i did a co-stream with last miles and we
were
working on actually it was it was we
were practicing hashes after
the hash lesson that we did um
and so i was just well i wasn't good i
was watching him
do stuff and uh define came in quite a
bit and it seems like it was it was
you're defining variables of a sort but
i wasn't sure if it was like not
variable variables
or again okay the hint here is the fact
that it has a pound in front of it
pound signifies something yeah well
not necessarily it means the
pre-processor handles it the language
doesn't
okay so it's not it's part of the
language but it's kind of not
right you know you could you could
actually build a c implementation that
doesn't do this at all
in fact early c compilers the
preprocessor was a separate program from
the actual like compiler
yeah these were usually like m4 you know
there were different macro packages that
were responsible for this
define does not create a variable that
would actually involve like building
storage and stuff like that
define literally means when you see this
put that okay
and that's it it's an alias kind of it
kind of except it's really literal
like if if you come along and you say
like print f
this was pretty cool
oh even in like it's it has no
knowledge of the language okay
it's it's handled by the pre-processor
it is not handled by the language
so that that's important it's
that specific okay there we go i feel
like there could be some danger
just like there's a huge danger this
huge danger
this allows you to write the worst c
imaginable
you could say things like define main
to be not main and this program will
fail from now on
oh you you could say pound define
ins to be float so every time you
actually get an int it'll actually turn
it into a float
you this thing is a really
dangerous tool so like there's a reason
i did not really mention it in the
course
it also feels like another way to just
obfuscate your code
it actually the obfuscated c contest is
normally won by some really
crazy defines so um
there is sort of like a good and best
practice to define you know one of the
things is like well
don't and actually that kind of speaks
to what you were talking about earlier
like you know how did they do something
like you went 8t
well they did something sort of like if
you're on
if defined um risk
platform risk 5 platform
then and by the way there's some more
stuff that i wasn't talking about
um in the preprocessor but you could say
things like all right then
type def which is something else we
didn't talk about you in
a t all these dark side components like
they're they're they're dangerous okay
so so i don't feel comfortable talking
about them in
the basic intro to see cars like this is
this is this this really like for for
now
try not to do anything with the
preprocessor pre-processing
like focus more on the language if
you're reaching for the pre-processor
don't reach for the pre-processor okay
okay um there's actually uh
as as math just mentioned there's
actually a warning
this code shouldn't run
and by the way when you compile this
like
it no we don't have fftw installed so if
we
we we get that warning like you know
just when when you compile this thing it
will tell the person compiling it by the
way
just to let you know you know like
don't change this value
it's really cranky at the apostrophe so
i might take out that
um don't like you you can you can do all
sorts of
fun stuff um this uh we we could
actually fix this we could
we could quote it if we want um it
sort of depends on like yeah but you're
now you'll notice that maine is not
defined anymore
what what happened to maine
oh because of this i warned you
that's delicious and where that gets
really crazy is when you do it in one of
these includes so the programmer doesn't
even see it
that just seems like you're being a jerk
you know it's
there's reasons there's reasons
it's okay we're not going to get into
the
the wonders and the horrors of the
pre-processor
their owning is kind of giving you a
taste of the dark side just just
just stay away okay
just just just don't do it okay um
so anyway you should know that it's out
there
it's not really the basic c stuff
to be perfectly honest with you this
feels like the conversation that my
parents had with me
in um middle school about drugs yeah
like we wanted to know they're out there
but we don't
what yeah we don't want you to use
that's i feel like that's the only way
you can end the sea course
it's like okay now you have the kung fu
is this the gateway drug
you have the kung fu you need to be
never use the killing technique
okay like this is this is dangerous
stuff here okay so
it is it is our last conversation on
basic c
so um anyway that and by the way you can
turn off warnings
you know there's there's ways to turn
warnings off but i'm not gonna show you
that either
okay so um that's just the
last thing and that gets a little bit
into how multi-file support works
and see it actually was sort of bolted
on because originally you just wrote
everything in like one program
and then when you started wanting to
have multiple files that's when somebody
came up with this preprocessor and they
said oh i'll just take that file and
include it right here
and that's how it happened
[Music]
so we still deal with it that's
it's life all right
um when we compile things we do have to
worry about compiling
units and getting them to work together
and whether they were compiled by us
sometimes
we get code from a corporation say it's
commercial code
and they will not tell you the
implementation they will not ship it to
you
they'll say no that's our trade secret
we'll give you the library
and we'll give you a header file so that
you can call it but we're not going to
tell you we're not going to give you the
code because that's a trade secret
and wait
how it's just that the language grew up
in that era
you know you could get this special
library it's we're still there to this
day most of these days most of the time
it's hidden in firmware blobs these days
but
like you know or like a wi-fi driver or
say like a video card gpu driver that's
500 megabytes and big enough to say have
an entire operating system in it
including multiple compilers or whatever
else is in there
nvidia but so not not getting into that
but like
we we don't always get the
implementation
sometimes we actually just get a library
sometimes we get a linked ex
you know like a it depends on the link
format it's not not the actual extra
computer but they'll give you the linked
unit like this is the linker object
um you there's different ways these days
it's usually a shared library so they'll
just give you a shared library and
they'll say
we're not going to tell you how to
compile this thing we're not even going
to show you how it works but
here's your definitions and you can call
into it
[Music]
well that's the real life of a c
programmer
sometimes there's actually really good
reasons for being opaque like i'll tell
you one of the best
i mean trade secrets i understand no not
trade secrets um
that one almost always backfires it's
almost always a bad idea
it's usually better to like be on a
shared source type agreement but
so um one of the ways that that
usually um is useful say if you're in a
team
and it's not your responsibility like
say somebody has to build like
a good foia transform implementation
and that team just sits around building
the best fourier transform
or the best like jpeg decoder for arm
or the best like you know so say like
there's like you know this type of
specialization across a really large
organization
then okay you usually don't
care how they do it so in a sense you
can
look at the code because usually you
have access to the same code but
you kind of don't care you you as the
programmer
it's your job to consume that api so
you're basically just saying
look i'm calling your functions and they
don't work or they do work
so like it's kind of like the the the
details are opaque to me i
i don't care how you decode the jpeg i
care that you do a good job
okay that allows that type of boundary
between teams and
orgs and it can go across companies and
whatever so there actually are like
reasonable like
let people worry about their specific
like areas so
like you can have a team that's like
their specialty is just building
ridiculously fast like
recurrent neural networks and you don't
really care you care that the interface
doesn't change
right because that's how you're going to
call it but i guess
i don't know i've had way too much
experience with
bad code getting packaged and lauded as
good code
that i'm i'm very nosy now well that's
part of it is like
why do you care about the implementation
detail because that means something went
wrong
yeah that's we call that a leaky
abstraction
so like i just you never saw the code
for printf and did you ever care
no i guess why once once you get to a
certain
once you get to a certain level though i
think that
it becomes necessary i'm not sure you
know the details the reason i don't care
how print f
is written is that i don't care how
printf
is written i get that i'm saying that
like
especially thinking of ai and machine
learning
that dangerous things happen when people
hand wave and say it works and so i
don't need to understand the details
well that's where that stuff goes very
bad see that isn't
like printf why why do we trust printf
well because i think it's a lot simpler
not just this is it actually printf is
it has it
not simpler in what it not simpler in
its guts
but it's execution can be very easily
verified
and no actually it's really hard to
verify there's
there's certain organizations that won't
let you use it because it's a very attic
operator
and it causes like i mean so that's
actually printf is phenomenally
complicated
by the way okay um but the thing is
we trust it because it's rock solid you
know there's been
tons of years of engineering on it
there's like a lot there's a whole world
of like
good print def and bad print depth
there's conformance tests there's
there's all sorts of like standards that
say that this print def is functioning
correctly and this one is not yeah
exactly
so it's very it's very evolved code
and in a sense that's great for us
because from a point of abstraction we
don't care how it works
we just want to get some other task done
and we want to occasionally look at some
output
that's formatted right i still think
that once you get to
i guess when you if you don't want to
talk about complexity then i would say
when the further away you get from
something that is standardized
the more i i think you should scrutinize
it and that's just because
in my experience i've seen a lot of
problems happen when people just
sort of take it on faith that something
works because it works and it seems to
be working and we've run some tests and
it says it's accurate and it's
giving us the answers we expect or oh
this team built it so we're just going
to start using it
and i find that like the the
lack of like the unwillingness to look
under the hood
gets dangerous and i'm not saying you
need to go down to the level of
every single function you need to know
exactly you know
like nathaniel just mentioned you could
stop the processor you could look at the
assembly
it's always there i mean that's the
level of of i get i get your point
i think there's there is a distinction
though where you leave the realm
of kind of maybe it's the the standards
or i'm not sure but there definitely is
a boundary to that
and it can get really messy
when when you cross that boundary
because i feel like that
could i summarize your thought in
different words for a moment sure
could i say that given enough eyes all
bugs are shallow
sure i kind of like that yeah i mean if
we say
inspected a lot of the code and had a
lot of smart people looking at the code
and it was very transparent then yeah we
could start to believe that like
you know there's not a lot of bugs in
there we can deal with all those bugs
and
eventually we'll get pretty reliable
there's i think there's like kind of
hallmarks of of
wait before you tell me about the
hallmarks what do you think of that
quote
what that you have enough people look at
something given enough eyes
all bugs are shallow i think that
on the surface it sounds nice it makes
me worried because there's been plenty
of things that have passed
peer review that have been egregiously
wrong okay and it kind of is
it's it's rooted in sort of the same
ideas of you know
because the majority thinks it right it
must be right which is just not true
this is actually the argument for open
source
i'll let linus know about your your
disgruntlement with his comments but
it's fundamentally it is a good idea
that the more people you have
looking at something the more well this
was the argument for open source
versus closed source like hiding
implementation details
and exactly what you just said yeah i
think
what i was talking about is is less the
objective and more the subjective and so
with the objective facts of this code
doesn't work
i think absolutely but when there there
is there's always going to be
subjectivity and design and in
especially in like modeling and whatnot
and so i think
that's where that's where that starts to
break down because you can have
differences of opinion
pardon me amongst experts yeah i mean
what if you put the source first before
the destination
or the destination before the source
which we ran into and see
library stuff i mean two sets of experts
just chose two different ways of doing
it
and so two different libraries i'm
always looking at the manual pages
because
i mean both were reasonable you know
like it's you can't really say that
one's right and one's wrong in that case
yeah so that i mean i i think that what
you're getting at
is for ironing out
execution in a lot of ways the more
people we have looking at this and
inspecting it
and caring about it the more likely it
is that we're going to find those
problems but when it comes to areas of
subjectivity that's where you kind of
have more issues because
there could be two equally good ways of
doing something
and two people or two groups of people
could
argue about it till the end of time yeah
so i think it's important also to
distinguish between the
design and subjective kind of components
of
writing software and then the objective
sort of
is it actually doing what you think it's
doing is it running so nathaniel brings
up an interesting point to that which is
this notion of formal verification um it
is
pop there are techniques to basically
prove
that something does what it says it does
under all
right there there are i can tell you
that
a lot of these techniques are extremely
costly in terms of like human resources
and that
generally means in terms of time um
there are mathematical proofs you could
give to say like this is
correct this is provably correct code
c is not one of those languages that
likes to lend itself to that
but um there are languages that are
actually built entirely on that
like premise um okay
but that's we're we're learning c so i'm
giving you naked pointers and
you could do whatever in memory and you
know like you could take a void pointer
and turn it into a pointer and then
decide to change it to a care pointer
you know because you feel like it i mean
you know it's it's
it's not even like a formal verification
thing though it's it's and it doesn't
need to be you know
absolute proof or something it's that
i think that a certain degree of
skepticism is always healthy
and the further the trolls are out now
big time because what you think
the standards are the the more dangerous
it gets especially if it's just joe
schmo at your company has written this
code like
yeah i see joe has to be watched yeah
you gotta watch it no but yeah that's
what i'm saying you gotta have standards
i've seen too much code handed down
to project managers and whatnot
don't aren't technical at all and just
go oh it works oh you've thrown some
numbers at me and its accuracy is what
oh
cool all right sure we'll package this
up and sell it and then you know
somebody comes along a couple years
later opens it up and is like what the
heck is this
like that has been way too much of a
component of my job for me to just
go in and and trust on faith that things
do what they say they're gonna do
they say that's why they pay you the big
bucks but to
math's comment i actually missed this
earlier um
i feel like the header files are like
the instructions for your instructions
in a way have you encountered a
situation that you had to create
like your own headers for the code to
work with the way you intended
yes math that absolutely does happen
occasionally um
there's all sorts of screws like
sometimes like the definitions are no
good
um usually i mean i usually try to find
another library at that point rather
than
go through the trouble of like really
like
like what code is really worth it like
if they like
solve the p equals np problem in there
like okay i'll bother to figure out like
a decent header for that but like like
it you know your
your normal run-of-the-mill computer
science object it's like there's usually
another library there's usually a better
option and
you know and the the trolls are just out
in force right now so
like there there's there's a lot of
languages
that they're starting to throw around
which are much more serious
about um keeping the programmer from
doing harm they also sometimes keep the
programmer from doing any programming
it sort of depends what you want to
trade like do you want to trade
correctness i mean
like cobalt is pretty solid for that
you know you can you can really verify
that like the given inputs
and the output i mean it's like pretty
straightforward you know that's
anyway um we can go down that path i
think that that's a
well i think we're basically in the
discussion so before i
wrap this beautiful code editor that we
built
up um is there any uh
sequence there anything i missed that
you're like upset oh my god
you didn't mention that this is just not
a c
course okay is that fair enough but i
mean like is there something
someone told you about that you were
like oh man i was really hoping to learn
about
blah nobody i know except dennis knows c
okay actually so oh guy how could you
not
show the union like i didn't show the
union
love this sorry i i'm hopefully this
won't get too much i know we need to
like
officially sort of transition into the
storytelling time but
i cannot believe i forgot to tell you
this so
wait if this is a story then we're
transitioning okay all right i'll wait
then i'll wait no no i mean we'll
transition right now i'm just saying
like i think that's
hold that thought okay i'll hold it okay
you got it uh i don't think there's any
other i i think we're good i mean chat
is this keep me honest here is this a
legit version of c as an additional
language
i i want to hear your comments i want to
hear your feedback
actually i don't i don't want to hear
too much feedback
some honesty but not too much what is it
from interstellar like
honesty 90 or something yeah okay go go
honesty 90
um i think it's hard for me to ask
questions because
of the things that you've shown me i i
feel like i understand them
i agree with you that i want to practice
things a lot more
yeah i think that's the biggest failing
so far in this course that's that's on
me i just got to build a version of
multi-user pad
i think more projects and practice
is always good because i i i ran into
this problem with python when i was
first trying to learn it that i
i watched so many videos and read
so many articles on how to do stuff and
i just was like why
am i not getting it because that's how i
learned a lot of things is by
reading the textbook and then
it really just i exponentially grew
as a programmer when i started just
writing python every day
oh sure you know and so i think for me i
think there's no question having learned
that lesson
i want to continue um yeah no i i do too
practicing i'm gonna
wrap like the c a a c a
three l up
i think i think we can call that i think
we can call that a course i i mean
next i would definitely like doing it
again i would definitely add that in
the the whole um having a better
practice plays having a place where like
you can easily
work um i do like kind of like to what
nathaniel's bringing up now and
by the way i do agree that that's a
reasonable exercise i'd say that that's
not necessarily part of
the c course part of why i went after
this multi-user pad was because
we didn't have to get involved in any
environmental setup
there's no system set up there's no
updates there's no
like we just jump onto a web page and
we're coding like like we don't have to
worry about
any of it and that that's sort of by
design like i wanted to focus on
c more than like tool chains and you
know
compilers would be good to kind of have
a you know first time
setup type thing yeah yeah well we could
go do that that i think that's a good
you know what let's do that next time
let's actually make that the next
yeah i'm not going to call it part of
the c class but that
we'll go in enough you know we'll do a
shared like
i'll spin up an instance on ec2 and
we're just going to go from like this is
scratch hardware
how does that sound that sounds good
yeah
i don't want to do linux from scratch
we're not gonna we're not gonna build
the kernel to like start the system
right now
taking over what last miles does
all right so we'll say for the next
stream we'll do
um like configure an ec2 instance
all right that's cool i'm down with that
um that's the c
and ketchup prove oh cool all right well
it seems like they
yeah and the project ccve like we're
we're moving into the project what we're
working on
yeah scoping that out right now