1: Logic & Instances
We start with the fundamentals of logic gates and logical expressions using De Morgan's Law. By looking at transistors, the most granular aspect of CS, we can steadily add layers of abstraction.
Learning Targets
I can explain the connection between electricity and logic.
I can interpret logical statements with all common operators, (i.e. and, or, nor, xor, if, iff).
I can simplify a logical expression according to De Morgan's Laws.
I can convert numbers from decimal to binary and to hexadecimal.
I can describe the purpose of instantiation.
I can decide when to instantiate an object or when to use a static class.
Logic Gates
I'm absolutely fascinated in how people build logic, systems that react to conditions, into physical devices.
We start with two tricks with circuits:
1) and &&
2) or ||
With tiny transistors and these building blocks, we can assemble our modern technological era. Let's just take a peak:
De Morgan's Law
You'll need to know how to distribute the !
when simplifying logical expressions. This will make more sense as we get into more practical examples.
A "promise" or an "if" within logic is something like:
Practicing Boolean Logic
Let's simplify these statements. Reduce them down to just true
or false
true != true || (true || false)
false && true || true && false || true && false || true
!(true && false)
!(5 > 5)
!(5 <= 5)
5 == 5 && true
Binary
Can you see how false
and true
could also be considered to be 0
and 1
? All the sudden, we can make these logic gates, these electrical transistors, store binary data. Computers are pretty cool.
Instantiation
This is an important concept that's most easily introduced when we're not thinking about the code. If you have a recipe to make a cake, that's similar to a class definition. Each time you bake a cake, you're creating a new instance of that cake.
Another example of instance VS static classes
This is by no means a perfect example as things are more complicated... but let's consider Fortnite for a moment. There's just one map. Programmers might refer to this map by its class. If I wanted to call a tornado, at Coney Crossroads, I might type something like, Map.createTornado("Coney Crossroads");
Now let's imagine a programmer wanted to provide a player with some individual powers. I wouldn't want to be so broad as to call the whole Player
class as each player is an individual. I'd want to specify which individual player, something like lancerGuy99.upgradeWeapon();
Last updated