← all lessons
Foundations · #0 of 13

Welcome — Programming, and Why Rust

Starting from scratch: what a program is, and what makes Rust different

A language that started as one engineer’s nights-and-weekends side project now runs inside your browser, your operating system, and the servers behind your favourite apps. It is loved more than any other language on Earth, and it earned that love by being stubborn.

This is the story, and the mechanics, of why.

This curriculum assumes Rust is your first programming language. If you’ve coded before, the early lessons will move slowly — skim them. If you haven’t, every word matters; read it in order, don’t skip.

The goal isn’t to make you a Rust expert in a weekend. It’s to give you a working mental model of how a program executes, and how Rust specifically helps you build one without the categories of bugs that have plagued every other systems language for fifty years.

What is a program?

A program is a sequence of instructions that a computer follows. You write the instructions in a programming language — a language designed to be unambiguous so a computer can carry them out exactly. Different languages have different strengths. Some are tuned for quick experimentation, some for absolute speed, some — like Rust — for safety and speed at once.

A program does three kinds of thing:

  1. It holds data. Numbers, words, lists of things, files, network connections.
  2. It transforms data. Adds two numbers, splits a sentence into words, sorts a list.
  3. It produces output. Prints to your screen, writes a file, sends data over the network.

That’s it. Every program you’ve ever used — your browser, a game, the text editor these words were written in — is some elaborate combination of those three.

A few words you’ll need

Some terms come up constantly. Quick definitions, then we’ll see each in action:

What is Rust?

Rust is a systems programming language — meaning it can produce small, fast programs that run close to the metal: operating systems, browsers, databases, embedded devices. C and C++ have owned that territory for decades. They produce fast code, but they’re famously easy to crash: a forgotten check, a bad pointer, two threads stepping on each other’s data, and your program corrupts memory or, more often, just silently does the wrong thing.

Rust was built to be just as fast as C, but with the compiler enforcing — at compile time, before you even run the program — that those bugs are impossible to write. The defining feature is the borrow checker: a part of the compiler that tracks who owns each piece of data and refuses to build if you try to use data in an unsafe way.

The friction is the point. Rust is picky in the way a flight instructor is picky: every refusal is a lesson, and once you internalise the rules you stop making the class of mistake the rule was protecting you from.

The shape of the smallest program

Here’s the smallest complete Rust program. Don’t worry about understanding every character yet — just look at the shape, then change it and run it for real. (The code box below talks to the official Rust Playground, so the “Run” button compiles your edit with a real Rust compiler and shows you exactly what it prints.)

Your first program editable · real rustc
Open in Playground ↗ ready

Three things happen:

  1. fn main() { ... } defines a function called main. Rust starts every program by running the function named main. The { and } braces wrap the function’s body.
  2. let greeting = "hello, world"; creates a variable called greeting and points it at the text. The semicolon ends the instruction.
  3. println!("{greeting}"); calls a built-in tool called println! (the ! marks it as a macro — for now, treat it as “print a line”). The {greeting} gets replaced with the value of greeting when the program runs.

Try editing the greeting in the box above and hitting Run again. You just compiled Rust.

Why the compiler argues with you

If you’ve heard about Rust before, you’ve heard people say it’s hard. What they mean is the compiler rejects your code more often than other languages would, with longer error messages. That’s true. What’s also true:

Watch it happen. The program below tries to add a number to a piece of text — nonsense, and Rust refuses to build it. Hit Run and read the error; this is the picky-compiler experience in one screen.

A bug the compiler catches before it runs editable · real rustc
Open in Playground ↗ ready

Notice what didn’t happen: the program never ran and did something weird. The compiler stopped it at the door and explained why. In many languages this same mistake slips through to runtime and corrupts your output silently. Rust shifts the failure earlier, to the cheapest possible place to fix it.

A short history of a stubborn language

2006

Graydon Hoare starts Rust as a personal project. The earliest compiler is written in OCaml, since Rust can't yet compile itself.

2009

Mozilla begins sponsoring Rust, betting it can power Servo, an experimental, parallel browser engine that C++ made too dangerous to write.

2010

Rust is announced publicly for the first time. The ownership-and-borrowing model that defines the language is still years from settling.

2015

Rust 1.0 ships. From here on, code that compiles is promised to keep compiling — the stability guarantee that made companies willing to adopt it.

2021

The Rust Foundation forms, backed by Amazon, Google, Microsoft, Mozilla, and Huawei. Rust soon lands in the Linux kernel — the first language besides C and assembly allowed there in three decades.

What you’ll learn here

The next twelve lessons walk through Rust in roughly this order:

Every code box in this course runs for real — edit it, break it, fix it. That feedback loop is the fastest way to learn.

Why 'systems language' actually matters

Most popular languages — Python, JavaScript, Java, Go — run on top of a runtime that manages memory for you using a garbage collector: a background process that periodically scans for data no longer in use and frees it. Convenient, but it costs CPU time and introduces unpredictable pauses, which is unacceptable for an operating-system kernel, a game engine at 120 frames per second, or a tiny microcontroller with kilobytes of RAM.

Systems languages (C, C++, Rust) have no garbage collector. In C and C++ that means you manage memory by hand, and a single mistake — freeing the same memory twice, using a pointer after the data is gone — corrupts the program. Rust’s bet is that the compiler can prove your memory use is correct at compile time, giving you C-level speed with no garbage collector and no hand-managed-memory bugs. The rest of this course is mostly about how it pulls that off. The key idea has a name — ownership — and it’s lesson 4.

Key takeaways

Rust asks more of you at the start than almost any other language. In return it hands you something rare: the confidence that if it compiled, whole categories of bugs simply aren’t in there.

That trade — a little more thought now for a lot less debugging later — is the entire bet. The next twelve lessons teach you how to win it.