Latest / CyberSecurity Summary / C++ For Dummies
Transcript
- 0:00Speaker 1: So imagine you are hungry and you ask a friend
- 0:03Speaker 1: to make you a peanut butter sandwich.
- 0:04Speaker 2: Okay, sounds good, right.
- 0:05Speaker 1: You just say, hey, could you whip me up a
- 0:07Speaker 1: PB and J. Yeah, And they just do it. They
- 0:09Speaker 1: know to walk to the pantry, they get the bread,
- 0:11Speaker 1: they unscrew the jar.
- 0:12Speaker 2: Yeah, and they use a butter knife, not a spoon.
- 0:14Speaker 2: It is all entirely seamless.
- 0:16Speaker 1: Exactly because you both share this massive amount of unspoken
- 0:22Speaker 1: human context.
- 0:23Speaker 2: We really do. I mean, we rely on intuition to
- 0:26Speaker 2: fill in the gaps of our communication every single day.
- 0:29Speaker 1: But now imagine asking a painfully literal robot to do
- 0:33Speaker 1: that exact same thing. Oh boy, Yeah, you say, put
- 0:36Speaker 1: peanut butter on the bread. The robot grabs the unopened
- 0:39Speaker 1: glass jar and just smashes it directly into the loaf
- 0:42Speaker 1: of bread.
- 0:43Speaker 2: Crunch, glass and peanut butter everywhere.
- 0:45Speaker 1: Everywhere, because you know, you didn't explicitly tell it to
- 0:48Speaker 1: unscrew the lids, so it didn't.
- 0:50Speaker 2: It is basically the perfect recipe for disaster. When we
- 0:53Speaker 2: try to talk to machines, we realize very quickly just
- 0:57Speaker 2: how much we take our human intuition for granted.
- 1:00Speaker 1: We really do.
- 1:00Speaker 2: Yeah, we speak in generalities, but machines they only understand absolutes.
- 1:05Speaker 1: And that is exactly why you are joining us for
- 1:07Speaker 1: this deep dive today. We are looking at a world
- 1:11Speaker 1: completely devoid of human.
- 1:13Speaker 2: Intuition, a very literal world.
- 1:15Speaker 1: Super literal. The mission for our deep dive is to
- 1:18Speaker 1: explore how humans and machines actually communicate. And to do this,
- 1:24Speaker 1: we're using Steven R. Davis's book CLUS plus for Dummies
- 1:27Speaker 1: seventh edition as our guide today.
- 1:30Speaker 2: Which is great because it serves as a fantastic foundation
- 1:32Speaker 2: for this whole topic.
- 1:33Speaker 1: Absolutely, but just to be clear to you listening, our
- 1:37Speaker 1: goal today is not to have you memorize code or
- 1:40Speaker 1: like learn syntax.
- 1:41Speaker 2: No, we aren't building a mobile app here.
- 1:43Speaker 1: Right, No apps today. Instead, we want to look under
- 1:46Speaker 1: the hood of C plus plus to understand the really fascinating,
- 1:50Speaker 1: highly literal way that computers actually think.
- 1:53Speaker 2: We are going to see how a programming language acts
- 1:55Speaker 2: as this ultimate middleman, you know, translating our messy human
- 1:59Speaker 2: intentions into cold, hard binary reality.
- 2:02Speaker 1: Because the underlying truth of computing is that processes are
- 2:04Speaker 1: incredibly fast, but they are also incredibly stupid.
- 2:08Speaker 2: Right, they do not speak English, They don't understand the
- 2:10Speaker 2: concept of a sandwich.
- 2:11Speaker 1: At all, not even a little bit.
- 2:12Speaker 2: No, they only understand machine language, which is really nothing
- 2:17Speaker 2: more than an endless see of microscopic electrical signals turning
- 2:20Speaker 2: on and off billions of times a second.
- 2:22Speaker 1: Okay, let's unpack this, because if they only speak voltage
- 2:26Speaker 1: and we only speak human language, we obviously need a translator.
- 2:30Speaker 1: We do. It is like we need to draft a
- 2:33Speaker 1: peace treaty for this ultra efficient but painfully literal alien species.
- 2:40Speaker 1: And that, I guess is the role of an intermediate
- 2:43Speaker 1: language like C plus plus N.
- 2:45Speaker 2: That is a great way to put it. You, as
- 2:47Speaker 2: the human programmer, write what is known as a source
- 2:49Speaker 2: file in a text.
- 2:50Speaker 1: Editor, and that looks a bit like English, right, Yeah,
- 2:52Speaker 1: it looks a.
- 2:53Speaker 2: Bit like English combined with some heavy algebra. But the
- 2:55Speaker 2: computer still cannot read that source file. It is still
- 2:58Speaker 2: too human.
- 2:59Speaker 1: So what happens to it?
- 3:00Speaker 2: Well, a specialized program called a compiler has to step
- 3:03Speaker 2: in to bridge that gap.
- 3:04Speaker 1: Okay, I always hear that term compiling. Yeah, but what
- 3:07Speaker 1: is it actually doing mechanically? I mean, it is not
- 3:09Speaker 1: just reading the text aloud to the computer.
- 3:12Speaker 2: No, it is entirely reconstructing it. The compiler takes your
- 3:15Speaker 2: human readable source file and meticulously translates it into object code.
- 3:19Speaker 1: Object code.
- 3:20Speaker 2: Okay, right, but it doesn't stop there. It then performs
- 3:23Speaker 2: a process called linking.
- 3:25Speaker 1: What does linking do think of linking?
- 3:26Speaker 2: Like taking different chapters written by different authors. Maybe you
- 3:29Speaker 2: wrote one chapter and a standard C plus plus library
- 3:34Speaker 2: provided another chapter. Oh I see, yeah, and it binds
- 3:37Speaker 2: them all together into one cohesive, executable book that the
- 3:41Speaker 2: computer's processor can actually open and run.
- 3:44Speaker 1: That makes sense. And C plus plus is uniquely positions
- 3:48Speaker 1: for this kind of heavy lifting, isn't it. Yeah, because
- 3:50Speaker 1: the source mentions it is certified as a ninety nine
- 3:53Speaker 1: point nine percent pure standard.
- 3:55Speaker 2: Yes, and it is considered a low level language.
- 3:58Speaker 1: Which honestly sounds like an insult, like it is less
- 4:01Speaker 1: sophisticated or something.
- 4:02Speaker 2: It does sound bad, But in this world, being low
- 4:04Speaker 2: level is a massive compliment.
- 4:06Speaker 1: Really. Why is that?
- 4:07Speaker 2: Because being low level means it operates very close to
- 4:10Speaker 2: the physical hardware of the computer. There are fewer layers
- 4:13Speaker 2: of abstraction between your code and the actual silicon chips.
- 4:17Speaker 1: Oh wow, so you are right down there near the metal.
- 4:20Speaker 2: Exactly that proximity to the metal is why C plus
- 4:23Speaker 2: plus is heavily used for things where performance absolutely counts,
- 4:28Speaker 2: things like high end video games, graphics, rendering, direct hardware control.
- 4:32Speaker 1: So it is blazingly fast.
- 4:34Speaker 2: Extremely fast, but because it sits so close to the hardware,
- 4:38Speaker 2: it forces the programmer to be incredibly precise.
- 4:41Speaker 1: It demands that precision because, like we said earlier, it
- 4:44Speaker 1: totally lacks that human intuition. Right.
- 4:46Speaker 2: A computer does exactly what it is told, nothing more
- 4:49Speaker 2: and nothing.
- 4:50Speaker 1: Less, and C plus plus enforces this reality through some
- 4:54Speaker 1: incredibly strict grammar rules.
- 4:56Speaker 2: Right, oh, violently strict. For instance, the compiler will completely
- 5:00Speaker 2: ignore all the blank spaces or tabs or empty lines
- 5:03Speaker 2: you put in your code.
- 5:04Speaker 1: Wait, really, even if I format it nicely so I
- 5:05Speaker 1: can read it yep to.
- 5:06Speaker 2: The machine, that is just called white space, and it
- 5:09Speaker 2: just throws it out. It does not care about your formatting.
- 5:12Speaker 2: But it is obsessively strict about capitalization.
- 5:15Speaker 1: Right the case sensitivity, because if you type I int
- 5:17Speaker 1: in all capital letters, it means absolutely nothing to the computer.
- 5:21Speaker 2: Nothing at all. It will just stare at you blankly
- 5:24Speaker 2: and probably throw an error that crashes your entire bills.
- 5:27Speaker 1: But if you type in in all lowercase letters.
- 5:30Speaker 2: Suddenly it understands you perfectly. It knows you are giving
- 5:32Speaker 2: it specific vital command.
- 5:34Speaker 1: That is wild. This strict literal nature really dictates everything
- 5:40Speaker 1: about how we interact with the machine.
- 5:41Speaker 2: It dictates everything. We can't just throw vague concepts or
- 5:45Speaker 2: you know, floating ideas at a processor.
- 5:47Speaker 1: So what do we do instead?
- 5:48Speaker 2: We have to package our data, our numbers, our text,
- 5:51Speaker 2: our logical states. We have to put them into very specific,
- 5:55Speaker 2: rigid containers before the machine will even acknowledge them.
- 5:58Speaker 1: Okay, so if the computer is this pain fully literal
- 6:00Speaker 1: with our commands, how does it handle our actual information?
- 6:04Speaker 2: Well, it uses variables, right.
- 6:06Speaker 1: But if I think about basic algebra, a variable is
- 6:08Speaker 1: just the magic box. You say x equals one, and
- 6:11Speaker 1: then later you can say x equals an entire sentence,
- 6:13Speaker 1: and the math just rolls with it.
- 6:15Speaker 2: Yeah, human math is flexible like that. But C plus
- 6:18Speaker 2: plus does not allow that kind of freedom, not at all.
- 6:21Speaker 1: You have to tell the computer exactly what shape the
- 6:24Speaker 1: box is before you are allowed to put anything inside
- 6:27Speaker 1: it exactly.
- 6:28Speaker 2: C plus plus is what we call a strongly typed language.
- 6:31Speaker 1: Strongly typed.
- 6:32Speaker 2: Yes, every variable is essentially a holding tank and you
- 6:36Speaker 2: must declare the exact type, the exact physical dimensions of
- 6:40Speaker 2: that holding tank in the computer's memory before you ever
- 6:42Speaker 2: use it.
- 6:43Speaker 1: And the most common box is that lowercase T we
- 6:45Speaker 1: just mentioned right, which stands for integer.
- 6:47Speaker 2: Right, whole numbers one to negative fifty.
- 6:50Speaker 1: But relying on integers introduces a massive mechanical flaw. The
- 6:55Speaker 1: book calls it the truncation problem.
- 6:57Speaker 2: Yes, this is where the literal nature of the machine
- 7:00Speaker 2: really bites the programmer.
- 7:01Speaker 1: Let me use a real world analogy to explain how
- 7:04Speaker 1: bizarre this is to you listening. Imagine you are trying
- 7:07Speaker 1: to split three leftover pizzas among three friends.
- 7:10Speaker 2: Okay, you, me and another buddy.
- 7:12Speaker 1: Right, But the accountant managing our pizza party only understands
- 7:16Speaker 1: whole pizzas. They are literally incapable of comprehending a fraction.
- 7:20Speaker 2: They do not have the mental architecture for a slice.
- 7:23Speaker 1: Exactly an integer. Only accountant handling the catering.
- 7:26Speaker 2: That sounds terrible.
- 7:28Speaker 1: It is. So we have three pizzas. I take the
- 7:30Speaker 1: first one and divide it by three people. The account
- 7:33Speaker 1: looks at it and says, one divided by three is
- 7:35Speaker 1: less than one whole pizza. Therefore, the result.
- 7:38Speaker 2: Is zero, and they physically take the slices and throw
- 7:40Speaker 2: them into the.
- 7:41Speaker 1: Trash, right into the trash. You take the second pizza
- 7:44Speaker 1: divide by three, the accountant truncates it again zero into.
- 7:48Speaker 2: The trash, and our buddy does the same thing zero exactly.
- 7:52Speaker 1: We started with three hole pizzas, we divide them up
- 7:55Speaker 1: to eat, and the computer mathematically calculates that we now
- 7:58Speaker 1: have zero plus zero plus zero, which is zero pizzas.
- 8:03Speaker 2: It is infuriating to a human, but it is flawlessly
- 8:06Speaker 2: logical to the machine.
- 8:07Speaker 1: That is so frustrating.
- 8:09Speaker 2: It is if you use integer math in C plus
- 8:12Speaker 2: plus to divide one by three, the fractional part isn't
- 8:15Speaker 2: rounded down, it is simply lopped off.
- 8:18Speaker 1: It just vanishes.
- 8:19Speaker 2: It vanishes into the ether because the integer holding tank
- 8:22Speaker 2: literally has no physical memory space to store a decimal point.
- 8:25Speaker 1: Wait, so if it just throws away the traction, I
- 8:27Speaker 1: am literally losing data every single time I do basic.
- 8:30Speaker 2: Division, every single time.
- 8:32Speaker 1: Why on Earth can't the computer just figure it out? Yeah,
- 8:35Speaker 1: why can't it just see that one divided by three
- 8:37Speaker 1: is a third?
- 8:38Speaker 2: Well, the creators of the language did provide a tool
- 8:40Speaker 2: to handle fractions, but it comes with a significant architectural.
- 8:44Speaker 1: Catch, of course it does. What is the catch?
- 8:47Speaker 2: To store decimals, you have to use a completely different
- 8:49Speaker 2: type of holding tank, a variable type called a float,
- 8:53Speaker 2: which is short for floating point number.
- 8:56Speaker 1: Oh, or you can use its bigger cousin the double
- 8:58Speaker 1: right exactly.
- 8:59Speaker 2: The boxes are specifically engineered to handle the decimal point.
- 9:03Speaker 1: Oh. Perfect problem solve, Then we just use floats for
- 9:06Speaker 1: everything and fire the integer account.
- 9:08Speaker 2: If only were that simple. There is a constant, unavoidable
- 9:12Speaker 2: trade off in computer science between speed and accuracy. Ah
- 9:16Speaker 2: the catch right, Integers are lightning fast. The computer's processor
- 9:20Speaker 2: can crunch millions of integer calculations in the blink of
- 9:23Speaker 2: an eye because they are so simple exactly. Floats require
- 9:27Speaker 2: vastly more computational work. But the real danger isn't just
- 9:31Speaker 2: the speed. It is that floats introduce round off errors.
- 9:35Speaker 1: Round off errors because a computer, as a physical object
- 9:38Speaker 1: doesn't understand the concept of infinity precisely.
- 9:42Speaker 2: Mathematically, one divided by three is point three three three
- 9:45Speaker 2: repeating forever right infinitely. But a computer only has a
- 9:49Speaker 2: finite amount of physical memory. A float variable can only
- 9:53Speaker 2: hold about seven digits of accuracy before it runs out
- 9:55Speaker 2: of space, so it just stops. It stops. It stores
- 9:58Speaker 2: that infinite concept as a very finite three point three
- 10:02Speaker 2: three three three three three. And if you take that
- 10:04Speaker 2: float and multiply it back by three, you do not
- 10:07Speaker 2: get ten. You get nine point nine nine nine nine.
- 10:09Speaker 1: Oh well, think about that. If you are checking out
- 10:12Speaker 1: of an online cart or looking at your banking app,
- 10:14Speaker 1: someone is stealing fractions of ascent.
- 10:16Speaker 2: Yeah, the math just doesn't add up perfectly.
- 10:18Speaker 1: Or worse, if you are calculating the trajectory of a
- 10:20Speaker 1: spacecraft returning to orbit, nine point nine nine nine nine
- 10:24Speaker 1: is not ten. That tiny missing fraction could mean missing
- 10:27Speaker 1: the atmosphere entirely.
- 10:28Speaker 2: It is a real problem. Now, the larger double box
- 10:31Speaker 2: tries to mitigate this.
- 10:32Speaker 1: How much larger is it?
- 10:33Speaker 2: Well, an inbox has a limit of about two billion,
- 10:36Speaker 2: which sounds enormous until you realize modern processors perform billions
- 10:40Speaker 2: of operations every single second.
- 10:42Speaker 1: Right, they chew through two billion instantly exactly.
- 10:45Speaker 2: The double box can hold massively larger numbers, up to
- 10:48Speaker 2: ten to the thirty eighth power.
- 10:50Speaker 1: That is a staggering number.
- 10:51Speaker 2: It is huge. But even the mighty double starts losing
- 10:55Speaker 2: accuracy and generating garbage data after about thirteen or sixteen digits,
- 11:00Speaker 2: you just can't win. You really can. You can have
- 11:03Speaker 2: massive numbers with loose precision or small numbers with type precision,
- 11:07Speaker 2: but the physical limits of memory mean you cannot have both.
- 11:10Speaker 1: So we are basically forced to store our data in
- 11:14Speaker 1: these inherently flawed containers. We have integers that are blazingly
- 11:18Speaker 1: fast but throw away fractions, and floats that are mathematically
- 11:22Speaker 1: precise but slightly inaccurate.
- 11:24Speaker 2: That is the reality of the hardware.
- 11:26Speaker 1: But once you have your data sitting in those flawed boxes,
- 11:28Speaker 1: you have to make them interact. You have to get
- 11:30Speaker 1: the computer to actually make decisions.
- 11:32Speaker 2: And getting a machine to make a logical choice based
- 11:35Speaker 2: on that flawed math is surprisingly dangerous. I can imagine
- 11:38Speaker 2: decision making is what makes a program appear intelligent. You know,
- 11:42Speaker 2: if this specific condition happens, execute that specific command in C.
- 11:46Speaker 1: Plus plus ah. The core of that decision making process
- 11:49Speaker 1: is boolean logic, isn't it, which is handled by a
- 11:52Speaker 1: tiny variable type called bool.
- 11:54Speaker 2: Yes, named after George Boole, the nineteenth century mathematician.
- 11:58Speaker 1: Right, and a bool variable is the simplest box of all.
- 12:02Speaker 1: It can only hold one of two values true.
- 12:04Speaker 2: Or false exactly, though in the early days C plus
- 12:08Speaker 2: plus just use integers to represent this logic.
- 12:11Speaker 1: How does that work?
- 12:12Speaker 2: A zero meant false and absolutely any other number meant true.
- 12:16Speaker 1: Oh that is interesting. That still works under the hood today.
- 12:19Speaker 1: But using the words true and false makes the code
- 12:22Speaker 1: much more readable for humans.
- 12:23Speaker 2: It definitely does.
- 12:25Speaker 1: But here's where that strict, unforgiving grammar comes back to
- 12:28Speaker 1: haunt us. Let's talk about the catastrophic difference between typing
- 12:32Speaker 1: a single equal sign and typing two equal signs.
- 12:35Speaker 2: Oh man, this is a rite of passage. Every programmer
- 12:38Speaker 2: makes this mistake at least once. Really, Oh yeah, A
- 12:41Speaker 2: single equal sign is an assignment operator. It is a command.
- 12:45Speaker 2: A command right, It means take the value on the
- 12:48Speaker 2: right side and violently shove it into the box on
- 12:50Speaker 2: the left side.
- 12:50Speaker 1: Shove it in there, okay.
- 12:52Speaker 2: But two equal signs is an entirely different concept. It
- 12:56Speaker 2: is a question. It means are these two things currently identical?
- 13:01Speaker 1: So if I am writing code for an e commerce
- 13:03Speaker 1: site and I want to ask the computer is the
- 13:06Speaker 1: user's shopping cart equal to zero? But I accidentally use
- 13:10Speaker 1: one equal sign, then you are in trouble because I'm
- 13:13Speaker 1: not asking a question anymore. I am actively emptying their cart.
- 13:17Speaker 1: I am commanding the computer to set their cart to.
- 13:20Speaker 2: Zero, and the compiler will happily execute that command. Even
- 13:23Speaker 2: if you buried it inside an if.
- 13:25Speaker 1: Statement, It just does it.
- 13:26Speaker 2: It views the destruction of the shopping cart as a
- 13:29Speaker 2: highly successful operation. It ruins the entire logic of your program.
- 13:32Speaker 1: That is terrifying.
- 13:34Speaker 2: It is. But even if you master the grammar and
- 13:36Speaker 2: use the double equal sign correctly to ask a question,
- 13:39Speaker 2: you still run headfirst into the math quirks we just discussed.
- 13:42Speaker 2: Oh right, You should virtually never use the equality operator
- 13:46Speaker 2: the double equals to compare two floating point numbers.
- 13:49Speaker 1: Because of the roundoff errors we talked about. Exactly, if
- 13:51Speaker 1: the computer is asking is ten exactly equal to nine
- 13:55Speaker 1: point nine nine nine nine, it will boldly shout false,
- 14:01Speaker 1: even though any human looking at the equation knows the
- 14:03Speaker 1: math was supposed to result in ten.
- 14:06Speaker 2: Exact equality is a total myth when it comes to floats,
- 14:09Speaker 2: because of the microscopic inaccuracies and how they are stored,
- 14:12Speaker 2: you always have to ask if they are close enough.
- 14:15Speaker 2: Close enough, Yeah, you have to write extra code to
- 14:17Speaker 2: check if the difference between the two numbers is incredibly small.
- 14:20Speaker 2: Rather than asking if they match.
- 14:21Speaker 1: Perfectly, that is so tedious. But the way the computer
- 14:25Speaker 1: evaluates multiple logical questions at once is where it gets
- 14:29Speaker 1: genuinely wild.
- 14:30Speaker 2: To me, Oh, you mean short circuiting.
- 14:31Speaker 1: Yes, C plus plus is secretly incredibly lazy.
- 14:35Speaker 2: Well, we prefer to call it ruthlessly efficient. In computer science,
- 14:39Speaker 2: we call this short circuit evaluation.
- 14:40Speaker 1: Okay, let me give an example. Let's say you have
- 14:42Speaker 1: a logical A and D statement. For example, I will
- 14:45Speaker 1: only go outside if it is sunny. A and D
- 14:48Speaker 1: I have my sound glasses.
- 14:49Speaker 2: Makes sense.
- 14:49Speaker 1: Both of those things must be true for the whole
- 14:51Speaker 1: sentence to be true.
- 14:52Speaker 2: Right In C plus plus A, you represent that A
- 14:55Speaker 2: and D with a double Ampersand.
- 14:56Speaker 1: Now if I look out the window and it is
- 14:59Speaker 1: pouring down, that first condition is its sunny.
- 15:03Speaker 2: Yeah is false, completely false.
- 15:05Speaker 1: And because it's an A and D statement, the entire
- 15:07Speaker 1: operation is already ruined. Doesn't it matter if I have
- 15:10Speaker 1: my sunglasses in my pocket or not, I'm not going outside.
- 15:13Speaker 2: And the computer's processor recognizes this inevitability, it does yes,
- 15:18Speaker 2: to save precious microseconds of processing power. If the first
- 15:23Speaker 2: condition in an A and D statement evaluates to false
- 15:26Speaker 2: C plus plus completely ignores the second condition.
- 15:29Speaker 1: It just skips it.
- 15:30Speaker 2: It's short circuits. It refuses to even look at the
- 15:32Speaker 2: rest of the line of code. The same logic applies
- 15:35Speaker 2: to an our statement too. If the first condition is true,
- 15:38Speaker 2: it skips the second one entirely because the overall statement
- 15:41Speaker 2: has already succeeded.
- 15:42Speaker 1: But think about the massive trap hidden in that laziness.
- 15:46Speaker 1: The side effects, Right, What if that second condition wasn't
- 15:49Speaker 1: just checking a value. What if it had actual operational
- 15:53Speaker 1: instructions baked into.
- 15:54Speaker 2: It, like the increment operator.
- 15:55Speaker 1: Exactly, the plus plus which tells a variable to increase
- 15:59Speaker 1: its value by one.
- 16:00Speaker 2: This is a classic example of silent failure.
- 16:03Speaker 1: Explain how that works.
- 16:04Speaker 2: Imagine you write a complex statement that says, is variable
- 16:07Speaker 2: A greater than variable B A and d is variable
- 16:10Speaker 2: C plus plus greater than variable D.
- 16:12Speaker 1: Okay, So if variable A is not greater than b,
- 16:15Speaker 1: the computer stops dead in its tracks.
- 16:18Speaker 2: It never even glances at variable C, which means variable
- 16:21Speaker 2: C never gets incremented.
- 16:23Speaker 1: Never happened if variable C was supposed to be tracking,
- 16:25Speaker 1: like how many times a player tried to log in,
- 16:28Speaker 1: or how many seconds had passed, that data is just gone.
- 16:31Speaker 2: It is lost forever.
- 16:33Speaker 1: The program didn't crash, it just silently failed to do
- 16:36Speaker 1: its job because the computer was trying to save a microsecond.
- 16:38Speaker 2: And this is why we have to ask, how do
- 16:40Speaker 2: you build a stable, reliable digital world when your foundational
- 16:45Speaker 2: tools behave.
- 16:45Speaker 1: This way it seems impossible.
- 16:47Speaker 2: The answer is a philosophy called defensive programming.
- 16:50Speaker 1: Defensive programming, Yeah.
- 16:52Speaker 2: Writing code isn't just about getting the syntax right so
- 16:54Speaker 2: the compiler doesn't throw an air. It is about deeply
- 16:57Speaker 2: anticipating how the machine will stock yiberally lazily optimize your logic.
- 17:02Speaker 1: You have to outsmart it.
- 17:04Speaker 2: You have to actively protect the program from the machine's
- 17:07Speaker 2: own ruthless efficiency.
- 17:09Speaker 1: It's almost like you have to stop thinking like a
- 17:11Speaker 1: human and start thinking like the machine just to control it.
- 17:14Speaker 2: You really do.
- 17:15Speaker 1: And all of that ruthless efficiency, you know, the stript rules,
- 17:18Speaker 1: the flawed math, it all stems from the physical hardware.
- 17:22Speaker 2: Itself, the actual silicon, which.
- 17:24Speaker 1: Brings us to the very bottom layer of our deep dive. Today,
- 17:28Speaker 1: we've talked about how C plus plus translates human logic,
- 17:32Speaker 1: but what is it actually translating into down at the
- 17:35Speaker 1: absolute bottom.
- 17:36Speaker 2: It is translating it all the way down to the
- 17:37Speaker 2: metal to pure binary.
- 17:39Speaker 1: See human math feels so absolute, like a universal law,
- 17:43Speaker 1: but it's totally biological when you think about.
- 17:45Speaker 2: It, very biological.
- 17:46Speaker 1: We count in base ten the decimal system, we use
- 17:50Speaker 1: the digit zero through nine. Why do we do that
- 17:53Speaker 1: because we have ten fingers.
- 17:55Speaker 2: If human beings had evolved with twelve fingers, our entire
- 17:58Speaker 2: mathematical foundation from birth would be base twelve.
- 18:01Speaker 1: That is so weird to think about it.
- 18:03Speaker 2: But computers don't have human hands. They essentially have two fingers.
- 18:06Speaker 2: They are built out of billions of microscopic electrical switches,
- 18:10Speaker 2: and a physical switch can only exist in one of
- 18:12Speaker 2: two states, on or off, true or false one or
- 18:16Speaker 2: is zero.
- 18:17Speaker 1: Base two binary. You know, there's a great joke in
- 18:21Speaker 1: the source material about this. If my dog had invented
- 18:23Speaker 1: a number system, it would be base eight or octal
- 18:27Speaker 1: base eight. Yeah, because if you look at a dog's
- 18:29Speaker 1: front pause, he's only got eight visible toes.
- 18:31Speaker 2: That is hilarious but completely true. It illustrates perfectly how
- 18:35Speaker 2: arbitrary counting systems really are.
- 18:37Speaker 1: Totally arbitrary.
- 18:38Speaker 2: The math works identically in any base but reading base
- 18:40Speaker 2: two is a nightmare for human eyes.
- 18:42Speaker 1: It can't even imagine, like the number.
- 18:43Speaker 2: One twenty three in our familiar decimal system translates to
- 18:47Speaker 2: zero one one, zero eleven in binary.
- 18:50Speaker 1: That's just visual noise.
- 18:52Speaker 2: It is your eyes just glaze over trying to parse
- 18:54Speaker 2: a screen full of that.
- 18:55Speaker 1: So how do programmers deal with that visual noise without
- 18:58Speaker 1: going completely cross eyed?
- 18:59Speaker 2: They create mental bridges. First, they group those individual binary digits,
- 19:03Speaker 2: which we call bits, into packages.
- 19:05Speaker 1: Of eight and that is a byte.
- 19:06Speaker 2: Yes, an eight bit package is a byte. And to
- 19:09Speaker 2: make those bites readable to humans, programmers use hexadecimal.
- 19:13Speaker 1: Hectadesimal, which is base sixteen right, and hexadecimal uses the
- 19:16Speaker 1: numbers zero through nine, and then it borrows the letters
- 19:19Speaker 1: A through f to represent the numbers ten to fifteen
- 19:22Speaker 1: right exactly.
- 19:23Speaker 2: By using base sixteen, programmers can compress that long, dizzying
- 19:27Speaker 2: string of ones and zeros into something short, punchy, and
- 19:31Speaker 2: recognizable like seven.
- 19:33Speaker 1: B seven B That is way easier to read.
- 19:36Speaker 2: It doesn't change the underlying on and off switches. It
- 19:39Speaker 2: just acts as a visual shorthand a bridge between the
- 19:42Speaker 2: physical silicon switches and human comprehension.
- 19:45Speaker 1: Wait, we don't just process numbers. What about characters, text,
- 19:48Speaker 1: the alphabet, All of that has to become numbers too.
- 19:51Speaker 2: Right, Absolutely it does. When you declare a chart variable
- 19:54Speaker 2: in C plus plus to hold a single letter or
- 19:56Speaker 2: a wide char for bigger characters, the computer is secretly
- 19:59Speaker 2: just storing a number that corresponds to that letter in
- 20:02Speaker 2: a massive index.
- 20:03Speaker 1: Oh, like a secret code.
- 20:04Speaker 2: Basically, the capital letter A might just be the number
- 20:07Speaker 2: sixty five.
- 20:08Speaker 1: Okay, I see, But as.
- 20:09Speaker 2: Software expanded globally, we needed much bigger boxes to hold
- 20:13Speaker 2: thousands of unique symbols for complex languages like Chinese or Arabic.
- 20:17Speaker 1: Right, sixty five only gets you so.
- 20:18Speaker 2: Far, exactly. That is why encoding formats like UTF eight,
- 20:23Speaker 2: UTF sixteen, and UTF thirty two were created.
- 20:26Speaker 1: I've seen those terms in my browser settings. Yeah.
- 20:28Speaker 2: They use more bits, meaning more physical switches to provide
- 20:32Speaker 2: enough unique numerical combinations to represent every single human symbol
- 20:36Speaker 2: on Earth.
- 20:37Speaker 1: Wow. When you really step back and look at this
- 20:39Speaker 1: entire system, all of those strict C plus plus grammar rules,
- 20:44Speaker 1: the intruncation throwing away pizza slices, the float round off errors,
- 20:48Speaker 1: dropping digits, the lazy short circuiting a and d statements.
- 20:51Speaker 1: It is a lot to take in, it is, but
- 20:54Speaker 1: they all exist because we are attempting an impossible magic trick.
- 20:57Speaker 2: How do you mean?
- 20:58Speaker 1: We are taking the incredible, complex, nuanced analog reality of
- 21:02Speaker 1: human existence and we are forcing it through a tiny,
- 21:06Speaker 1: rigid physical pipe of billions of microscopic switches that can
- 21:09Speaker 1: only ever say yes or no.
- 21:10Speaker 2: That is exactly what programming is.
- 21:12Speaker 1: And what does this all mean for you listening to
- 21:14Speaker 1: this deep dive right now? It means that every single
- 21:17Speaker 1: app you use on your phone, every high definition video
- 21:20Speaker 1: you scream to your TV, every digital photograph you've ever
- 21:23Speaker 1: taken of your family, it.
- 21:24Speaker 2: Is all ultimately just a carefully orchestrated illusion.
- 21:27Speaker 1: It really is. It's a towering, fragile skyscraper built entirely
- 21:31Speaker 1: out of microscopic ones and zeros, bundled into bytes, abstracted
- 21:36Speaker 1: into hexadecimals, managed by flawed variables, and meticulously translated by compilers.
- 21:41Speaker 2: And that skyscraper is kept from collapsing every single day
- 21:44Speaker 2: by programmers who have learned exactly how to draft those
- 21:47Speaker 2: piece treaties with the alien intelligence of the processor.
- 21:50Speaker 1: C plus plus is our strict, uncompromising translator in that relationship.
- 21:55Speaker 1: Today we've explored the literal minded nature of data variables,
- 21:59Speaker 1: the hidden changers of computer math, the lazy efficiency of
- 22:02Speaker 1: short circuit logic, and the binary reality beneath the metal.
- 22:06Speaker 2: We covered a lot of ground, we did.
- 22:08Speaker 1: But before we wrap up, I had this realization during
- 22:10Speaker 1: our conversation about the increment operator. You know, the plus
- 22:13Speaker 1: plus we talked.
- 22:14Speaker 2: About earlier, Oh, the one that gets trapped in the
- 22:16Speaker 2: short circuit right.
- 22:17Speaker 1: Adding one to a number is the most common mathematical
- 22:20Speaker 1: action in all of programming. But the reason the plus
- 22:23Speaker 1: plus operator actually exists in C plus plus is because
- 22:26Speaker 1: early microprocessors in the nineteen seventies physically had a specific
- 22:31Speaker 1: hardware instruction wired into them just for adding one.
- 22:34Speaker 2: It was faster than general addition exactly.
- 22:37Speaker 1: Hardware memory and processing power were so unbelievably limited back
- 22:41Speaker 1: then that saving a few micro instructions was a massive deal.
- 22:45Speaker 1: So the software language evolved to include plus plus specifically
- 22:49Speaker 1: to take advantage of that one physical wire.
- 22:51Speaker 2: The physical constraints the hardware literally dictated the vocabulary of the.
- 22:55Speaker 1: Software, which leaves me with a chilling thought to end
- 22:57Speaker 1: on for you listening, if a physical wire from a
- 23:00Speaker 1: nineteen seventies microchip permanently altered how we write code today.
- 23:04Speaker 1: How much of our modern cutting edge software is still
- 23:06Speaker 1: being shaped by the past.
- 23:08Speaker 2: That is a great question.
- 23:09Speaker 1: The very code running global high frequency finance, or simulating
- 23:13Speaker 1: protein folding, or powering the artificial intelligence that is fundamentally
- 23:17Speaker 1: changing our world right now, how much of it is
- 23:20Speaker 1: still being steered by the invisible ghosts of nineteen seventies
- 23:22Speaker 1: hardware limitations.
- 23:24Speaker 2: It really makes you wonder who or what is actually
- 23:27Speaker 2: giving the instructions it does.
- 23:29Speaker 1: Next time you ask someone for a peanut butter and
- 23:31Speaker 1: jelly sandwich and they intuitively know not to smash the
- 23:35Speaker 1: glass jar into the bread, take a moment to be
- 23:38Speaker 1: grateful for human intuition. Absolutely, thank you for joining us
- 23:41Speaker 1: on this deep dive. Keep questioning the digital world around you.
- 23:45Speaker 1: We'll see you next time.