introduction to computer science
What Programming Is and How Programs Work
An introduction to programming, how instructions are written for computers, and how code becomes something a machine can execute.
In the previous chapter we learned that computer systems are built in layers:
Applications → Programming Languages → Operating Systems → Hardware
But this leads to a natural question:
How are applications actually created?
The answer is programming.
Programming is the process of writing instructions that tell a computer how to perform tasks.
These instructions form what we call a program.
What Is a Program?
A program is simply a set of instructions that a computer follows.
These instructions describe:
- what data to work with
- what operations to perform
- when to perform them
For example, a very simple program might describe how to:
- Read a number
- Add 10 to it
- Display the result
Even complex software — like web browsers, operating systems, or games — are ultimately just very large collections of instructions.
Why Humans Don’t Write Machine Code
At the hardware level, computers only understand machine instructions.
These instructions look something like this:
10110000 01100001
Or sometimes like this (assembly language):
MOV AL, 61h
Writing large programs this way would be extremely difficult for humans.
Early programmers in the 1940s and 1950s actually did write software this way, but it was slow, error-prone, and very hard to maintain.
To solve this problem, programming languages were invented.
Programming Languages
A programming language allows humans to write instructions in a form that is easier to read and understand.
For example, a simple program in Python might look like this:
number = input("Enter a number: ")
result = int(number) + 10
print(result)
This is far easier to understand than raw machine instructions.
Different languages exist for different purposes.
Examples include:
| Language | Common Uses |
|---|---|
| Python | scripting, data science, automation |
| JavaScript | web development |
| C | operating systems, embedded systems |
| Java | enterprise software |
| Go | backend systems and infrastructure |
But regardless of the language used, computers still ultimately execute machine instructions.
So something must convert human-readable code into machine-readable instructions.
Compilers and Interpreters
Programming languages rely on tools that translate code into something the computer can run.
There are two main approaches.
Compilers
A compiler converts an entire program into machine code before it runs.
graph LR
A[Source Code]
B[Compiler]
C[Machine Code]
D[Program Runs]
A --> B --> C --> D
Languages commonly compiled include:
- C
- C++
- Rust
- Go
Compiled programs tend to run very fast because the translation happens only once.
Interpreters
An interpreter reads and executes code line by line.
graph LR
A[Source Code]
B[Interpreter]
C[Execute Instruction]
A --> B --> C
Languages often interpreted include:
- Python
- JavaScript
- Ruby
Interpreted languages are often easier to experiment with, though sometimes slower.
What Happens When You Run a Program?
Let’s look at the full path from code to execution.
graph TD
A[Programmer Writes Code]
B[Compiler / Interpreter]
C[Operating System]
D[CPU Executes Instructions]
E[Hardware Performs Work]
A --> B --> C --> D --> E
Step-by-step:
- A programmer writes code in a programming language.
- A compiler or interpreter translates the code.
- The operating system loads the program into memory.
- The CPU executes the instructions.
- Hardware performs the required operations.
Even a simple program involves multiple layers working together.
Core Building Blocks of Programs
Although programming languages differ in syntax, most programs are built from the same fundamental ideas.
Some of the most important building blocks include:
| Concept | Purpose |
|---|---|
| Variables | Store data |
| Conditionals | Make decisions |
| Loops | Repeat actions |
| Functions | Organize reusable code |
| Data structures | Organize complex data |
We will explore these concepts in later chapters.
For now, the important idea is that programs are constructed from smaller logical pieces.
Programming as Problem Solving
Programming is not just about writing code.
It is primarily about solving problems.
The real process usually looks like this:
- Understand the problem
- Break it into smaller steps
- Translate those steps into code
- Test and improve the solution
This process is often called algorithmic thinking.
An algorithm is simply a clear set of steps for solving a problem.
Programs are how we teach computers to follow those steps.
Why Programming Matters
Programming is the foundation of modern software.
It is how we create:
- websites
- mobile apps
- operating systems
- games
- artificial intelligence
- data systems
Every digital tool you use exists because someone wrote programs that instruct computers what to do.
Learning programming is essentially learning how to communicate ideas to machines.
What Comes Next
Now that we understand what programming is, we can begin looking at how programs actually work internally.
In the next chapter we will explore one of the most important concepts in computer science:
Algorithms and computational thinking.
This will help us understand how complex problems can be solved step by step in a structured way.