Computer Programming Explained
This tutorial series is not for expert programmers this does not contain new information for you. I will using metaphors to explain computer programming concepts. Of course this will not be the true reality of how computers & programming actually work, just a stand in for you to grasp the concepts better in your mind.
Before we start I always recommend these videos to people, the Harvard CS50 series by professor David J. Malan or going through the course. Also I recommend Crash Course Computer Science it breaks things down and it’s the best series on explaining computer science on video, if you are not a big reader.

However, if you do like reading, and I do believe reading comprehension is a key factor in becoming a successful programmer. Speaking of comprehension, humans are terrible interpreters of the world around us, myself include. We use stories, models, symbols, images, and especially metaphors to comprehend or understand our world better.
That is true the power of computer science to process so of much of the world around us in large amounts into comprehensible symbols that it allows us to manipulate the world around us. So what makes computer science so valuable is making the world comprehensible to us.
Computer Science can be simply broken down into this graphics.
Input -> Black Box -> Output

When you click the keys on the board or click with your mouse. Even moving the mouse across the screen is a form of input. Your computer is taking in data and outputting that data back on the screen in the form of pixels.
Inside that black box i.e. your computer there are so many perfect sequences, calculations, and executions happening in milliseconds while you move your mouse, we could almost call it a miracle if it wasn’t for the real science and engineering that allows you to do it, in the first place.
The Blackbox is a mental model for you to apply to systems you don’t fully understand and the nature of they work. For example right now you look at computer and you don’t know how it works or if you try to describe how it works you will struggle. In this tutorial I am assuming you don’t know how does a computer truly work and that is ok. That is how we learn about our world around us is by applying blackbox box theory.
We tend to pull levers randomly to see what happens and we slowly piece together the puzzle of that mystery.
Now let’s try to breakdown what computer programming is?
Let’s say you write a recipe for apple pie that is (programming) and you give the Recipe as a (Input) to the Kitchen to cook i.e your (Computer/Blackbox) and the kitchen gives you Apple Pie (Output).
Recipe -> Kitchen -> Apple Pie
So what that means is, you are programming a set of instructions or like a “recipe” (Input) for the computer to follow step by step like a person to follow, to give you back an expected result, i.e. Apple Pie (Output).

Now let’s break this down further & expand on it! What is inside the black box!!! What is happening inside this Kitchen?
Let’s take this step by step. In this black box we see
1. Scripting (Recipe) as a Input
2. Interpreter (Cook) that translate your Recipe
3. Execution of your Script (Oven) the fire to cook the Apple Pie
4. Output (Apple Pie)

Let’s say you are a chef (a computer programmer!) and you write down your apple pie recipe.
A recipe again is just a set of instructions that someone can follow to make Apple Pie. A script in code is very similar,, its a set of instructions for the computer.
In python you would open a text editor or a integrated development environment IDE like (word processor) to create a file called a script that is your recipe. The script you write in code (python) is the recipe. Which the set of instructions a cook (computer) follows to make said apple pie (output).
Each line in your recipe is an instruction that the computer follows in a specific sequence, telling the cook exactly what to do!

Now let’s hand our recipe over to the computer. We run the script by typing into the terminal, I will show you how in the next chapter.
python script.py
python script tells the cook, i.e. the python interpreter to read the script (recipe). The interpreter will read the “English language” (python) and outputs it into binary, that is Machine language a code or language only a computer can understand.
In the world of programming, this cook is called the Python interpreter.
You can think of the interpreter as a bilingual person who understands both English and ‘Computer’ (binary code). You give them your script (which is written in a language closer to English), and they translate it into a language the computer understands, on the fly.

Now that the recipe is in binary, the computer can read the recipe step by step and create the pie, this what we call Execution. Let’s say the computer is a Kitchen that is decked out with all the ovens, dishwashers, plates, and etc.
The computer will follow the recipe step by step translating and execute each instruction as it goes using all its hardware parts the oven, dishwasher, and plates.
- It could chop the apple (Do calculations)
- mix the flour and egg (check conditional statements)
- Bake the pie (store some data)

So now that the execution was completed, a computer will output, which is the Apple Pie!!!!
Now what that you have a basic understanding of what is happening, I can show you live action of what is happening with python. We write the script and we run the script, and the CPU executes in milliseconds.
That is coding, it’s not magic.
However, you could be wondering what is machine code? & binary? What is actually doing the executing? What is the oven and dishwasher like? What is happening in those milliseconds, beyond running this script? if you are asking yourself these questions already you are on your way to becoming a successful programmer.
There a is magic happening that no one has explained to you.
Always ask yourself how does this work? and try to diagram that. This a technique will get you through so many difficult problems.
Well it starts at the interpreter & we break that down further, when we run the script or “give a recipe to the cook”

Inside of this interpreter, step we convert English “Python” which is a high level language into lower level language codes. It’s lower becauses its closer to the hardware versus being a language harder for computer to “understand”.

What I mean by “understand”, is a computer or computers doesn’t truly “understand” anything, only what we tell it to “understand”. We provide instructions and the logic modules within the computer decode and instruct parts of the computer to function as expected.
What a computer actually does is decode or break down the code of the programming language python into its own language bytecode to make calculations and deliver the results you want to see.
The purpose of the bytecode is so its portable it can be used between different computers & different hardware parts of the computer (Logic modules). This bytecode is the same recipe you wrote but just in a different language that another computer will read.
The cook or interpreter is actually a recipe itself, it’s a software program in code. A program that is running in the background, constantly on low amount of resources awaiting to be called on to simply to do its job that is translate python (english) into bytecode.
Instead this computer is a virtual computer its a computer inside a computer that reads your recipe and calculates all the instructions inside of the virtual computer it has many jobs.
- Runtime Environment
- Libraries
- Memory Management
- System Services

This python virtual machine or PVM does something called a Runtime environment. It’s basically a safe zone to run your code and check that it works perfectly before passing it the CPU & real hardware components.
That is why it’s called virtual it all takes space in memory and CPU calculations.

The Runtime environment is importing libraries or more code to execute the code you wrote and any material it will to finish the job.

The Runtime Environment is also storing variables into memory this is really important part of scripting and programming.
Let’s say you told the cook “Hey don’t forget the sugar”
So X = Sugar
The cook (computer) will put X into memory.
So the computer can get Sugar later for baking the apple pie.
The computer stores variables like X in memory to keep track of data values it needs for operations later on, enabling efficient data manipulation and retrieval as part of executing programs and algorithms. Why does memory matter?
Well without memory management, a computer would face resource depletion and system instability, as it would be unable to allocate, track, and recycle memory efficiently, leading to crashes and performance degradation.
System services are background processes that the operating system (OS) runs to handle core functionalities, such as managing hardware devices, executing software applications, managing file and network operations, and ensuring security and user permissions.
We can access memory, devices like GPUs, sound cards, bluetooth, networks, and files. This why we need a Runtime environment and virtual computer can access hardware in your computer and run code for it making sure it works correctly before actually running on it that hardware.

In the Runtime environment also has access to system services so while you can turn on the oven to make sure it works. Runtime environment makes sure you don’t forget to turn it off.
Speaking of correct the final thing your Runtime environment does is check your code for bugs it checks each line of code, making sure everything is exactly in the right place to execute correctly before passing it hot to the real computer.
So if your computer has limited memory let’s say 32 GBs (this is a amount in data) what we call Gigabytes. And in your script you want to save 33 GBs to memory you are triggering what’s called a overflow buffer, because you are overflowing the amount of memory your computer can store. its like you can over filled a bucket and that can kill/crash your computer.
So Runtime environment saves you, from making stupid mistakes, and it catches those things real fast to report back to you as a error, what we call a bug on screen. What is the difference
A bug is a flaw or error in a program that can cause it to behave unexpectedly or crash, whereas a virus is a type of malware designed to spread and harm computers, often by exploiting bugs or vulnerabilities.

So while its called Runtime environment its running your script real-time, each line is getting checked then passed as bytecode and translated into what we call machine code.

https://en.wikipedia.org/wiki/Binary_file
Machine code is the lowest-level programming language, consisting of binary or hexadecimal instructions that is a computer’s central processing unit (CPU) can directly execute. It is specific to the architecture of a computer’s CPU and represents the most fundamental layer of software execution, directly controlling the hardware to perform operations.
We can actually make machine code human readable and its called Assembly Language it has its own history.
Assembly language is a low-level programming language that uses mnemonic codes and symbols to represent machine code instructions, making them more understandable to humans. It acts as an intermediary between high-level languages and machine code, allowing programmers to write code that is closely aligned with a computer’s hardware operations while remaining somewhat readable.
Then this Assembly Language translates into binary?
What is binary? you ask? Well Binary is just how computers count.
We (humans) count in tens or base tens or what we call decimals.
We have been counting for thousands of years in base-ten. Mathematics of the Incas used it for economics, administration, bridge building geometry. Counted using rope & knots called Quipu to record data.

Computers count in 2s or base-2. it only uses two numbers to count that with a 0 – 1.
Why? well for reasons behind engineering and physics and how technology developed over history, it’s a long & complicated story. However, there are some computers that are able to count in base-3 or Trinary.
Back to Binary!
Again a computer only uses two numbers to count 0 and 1. it’s like a light switch on is 1 / off is 0. This 0 and 1 is a physical even think physics within the computer specifically circuits within chips that contain transistors.

When voltage is passed to that transistor, it’s called a bit. Electrons flow through to filing a space within a very small transistor its like hole that can contain electrons or not contain electrons so 1 it contains electrons and 0 it doesn’t contain electrons.
So a single bit can be composed in a string of bits.
A combination of bits in a total of 8 compose a byte.

So when you hear Megabyte its 1 MB = 1048576 bytes or Gigabyte is 1 is 1 billion bytes. When you combine bytes into a sequence or rearrange their order you create a code. That the computer can read that code really fast, with the help of CPU.
So when you hear someone say “3.8 Ghz” they mean GHz (gigahertz) CPU is the frequency of the “clock” its quartz crystal oscillates back and forth, which the CPU uses as time reference to make sure it counts on time making sure each “back and forth” creates signal 0 to 1.
This is how we compare the value between CPUs is the speed/performance of computer via its Gigahertz. So a 2.1 Gigahertz CPU or less “back and forth” versus the more “back and forth” 3.8 Gigahertz CPU is worse.
So the code we are passing here
01000001 01110000 01110000 01101100 01100101 01110011

it translates to A P P L E
So what is a CPU? its a chip. A chip is composed of circuits. Circuits are composed of logic gates, and logic gates are composed of transistors.
To get the most detail of video of how computer physically works I would recommend watching this video call “How a Computer Works – from silicon to apps” by Improbable Matter.
Remember a transistor can be a 0 or 1 it holds a bit. And if you connect transistors together and arrange them into architecture you create ability to create AND, OR, NOT statements in logic or boolean algebra or boolean logic. 0 is false while a 1 is true, you create what is called a truth table that makes higher levels of logic a computer uses to make complicated calculations.
So what does that mean if you have a burger that is True if you don’t that is False. if something is true it means customers are happy if you can give them a burger.

When you build with many transistors and logic gates you get a circuit. When you get many layers of circuits you get a chip. Many chips create the CPU.
In your modern MacBook with a M1 Ultra Chip, your single CPU has over 114 billion transistors on 7.7 inches square at 3.7 inches high.
Now what does CPU stand for? its called the Central Processing Unit. or CPU. Its where every single instruction is passed to create signals and calculations to distribute signals across the entire computer to other pieces of hardware
- Power supply
- Monitor
- GPU
- Network Interface
- Sound Card etc

So what does the CPU actually do while running your code? Well it’s takes a single instruction and runs that instruction through what’s called a CPU cycle.
This cycle starts with fetching the instruction from memory, guided by the Program Counter that tracks the sequence of operations. Next, the instruction is decoded to understand the required action, transforming binary data into a set of comprehensible commands.
The execution phase follows, where the CPU carries out the decoded instructions, potentially involving arithmetic operations, data movement, or other specific tasks, utilizing components like the Arithmetic Logic Unit (ALU). We will cover this later.
Some instructions necessitate accessing additional data from memory, which is done in the memory access step, either before or after execution, depending on the nature of the instruction.
Finally, the cycle concludes with the write-back step, where the results of the execution are saved back to memory or a CPU register for future use. This intricate cycle, blending fetching, decoding, executing, memory accessing, and writing back, allows the CPU to process complex instructions and perform the multitude of tasks required to run software applications, repeating this cycle at an astonishing rate to ensure the smooth operation of the computer system.
Ok so we going go step by step what happens within execution or CPU cycle, let’s zoom into execution.

this whole diagram describes a CPU cycle which I will break down we begin first at CPU
Machine code is passed or fetched as instructions to CPU
then those ‘recipe’ or instructions are stored again in memory or instructions were retrieved from memory and that binary or bits are called into transistors. The stored code is passed on to circuits that decode the machine code or binary or that sequence of bytes.
The decoding circuitry are just logics gate that take the sequence apart.
When it decodes the message it’s passed to another circuit called the Control Unit it controls signals and generates signals inside the CPU
The control unit sends signals to the Arithmetic Logic Unit its a circuit that does basic math and it has its own set of unique logic gates to calculate that math.

So after its done calculating it passes its result back into memory or back to Control Unit as confirmation.
The control unit distributes signal to other hardware like the oven here it turned it on for its first instruction. When its confirmed it turned on it sends a signal back to start the CPU cycle all over again.

This basic diagram to summarize what I just said, this is what CPU does is cycle over your recipe or script over and over again executing each instruction you wrote.
Here we put a Pie in the Oven CPU cycle repeats.

step 3 Bake Pie at Temp 300 CPU cycle repeats.
step 4 Show Pie (Output) CPU cycle repeats on stand by.
When a computer is turned on its constantly cycling within to give you the real fidelity of what you see on screen by using all its hardware.

Conclusion
Hopefully you have a baseline for understanding some computer science concepts and now you can harass the power of computer science for your own skills. This continuous on in series for python coding.
