1. Introduction to Programming
What is code, and why should you care?
Imagine you have the world's most literal-minded employee. This person will do exactly what you say β not what you mean, not what you intended, exactly what you said.
If you tell them to "make coffee" without specifying the steps, they'll stand there confused. But if you say: (1) fill kettle with water, (2) boil kettle, (3) add coffee grounds to cup, (4) pour boiling water over grounds... they'll make perfect coffee every time.
That employee is a computer. Programming is the act of giving it precise, step-by-step instructions. We call those instructions code. A program is just a set of instructions that a computer executes in order.
Your phone's weather app, a banking system, a self-driving car, Instagram's recommendation algorithm β they are all, at their core, a series of instructions telling the computer: do this, then this, then check this, then decide that.
A computer is incredibly fast and incredibly dumb. Your job as a programmer is to give it instructions precise enough that its speed becomes useful.
How Computers Execute Code
When you write code, something has to translate your human-readable instructions into something the computer's brain β the CPU (Central Processing Unit) β can actually execute. CPUs only understand one thing: machine code, which is a series of 1s and 0s (binary).
Here's the journey your code takes:
- You write code in a high-level language like Python or JavaScript
- A translator program (compiler or interpreter) converts it to machine code
- The CPU executes those instructions one by one, at billions of operations per second
- The result appears β on screen, in a file, or over a network
Understanding Software vs Hardware
Hardware is the physical stuff β the chips, the screen, the keyboard, the memory sticks. Software is the instructions that run on the hardware. You can't touch software; you can only run it.
Think of hardware as a piano and software as sheet music. The piano (hardware) makes sound possible. The sheet music (software) determines what song plays. A Beethoven symphony and a pop jingle can both run on the same piano β just like a game and a spreadsheet app can both run on the same laptop.
Writing Your First Program
Across almost every programming language, the first program anyone writes is one that displays a message. Here it is in Python:
And here's the same thing in JavaScript:
That's it. Two things are happening here: (1) we're calling a built-in function (print / console.log) that outputs text, and (2) we're passing it a string of text in quotes. You've just seen two core programming concepts β functions and strings β before we've even formally defined them. That's intentional.
Setting Up Your Development Environment
Your development environment is where you write and run code. Here's the minimum setup you need:
- Step 1 β Install Python: Go to python.org, download Python 3.x, and install it. Python comes with a REPL (a live coding playground) you can access by typing `python` in your terminal.
- Step 2 β Get a Code Editor: Download Visual Studio Code (VS Code) from code.visualstudio.com. It's free, fast, and used by millions of developers worldwide.
- Step 3 β Run Your First File: Create a file called `hello.py`, type `print("Hello, World!")`, save it, open your terminal in the same folder, and run:
If you saw that output, congratulations β you are now a programmer. Seriously. The first run is always the most meaningful.
Knowledge Check
Ready to test your understanding of 1. Introduction to Programming?