Lesson 1.1 · 6 min
What a program is
A computer is fast and completely literal. It does not guess what you meant: it does step one, then step two, then step three. A program is just that list of steps. Everything else in this course is a way of writing better lists.
Adds to ChatterboxNothing yet: you read the finished program first.
A list of steps
Think of a recipe. "Boil water. Add pasta. Wait eight minutes." Whoever follows it does the steps in order and does exactly what is written. A program is a recipe for a computer, except the computer has no common sense, so every step has to be spelled out.
Here is the smallest useful Rust program. You can run it right here: press Run.
$ cargo run
Hello from ChatterboxThree lines, and every piece has a job:
fn main()means "the program starts here". Every Rust program has exactly onemain.- The curly braces
{ }hold the steps that belong tomain. println!("…")is one step: print this text, then start a new line. The;at the end marks where a step finishes, like a full stop.
What does the second line of output say?
42 + 222
Reveal the answer
The program prints: 4 The first step prints the text 2 + 2 =. The second step prints the result of working out 2 + 2, which is 4. The {} is a hole that the value after the comma fills in. We will use that a lot.
Writing is not running
What you type is just text, and a computer cannot run text. Rust has a helper called the compiler that reads your text and turns it into a real program the computer can run. That translation is called compiling.
So there are two moments: the compiler reads your code (compile time), then the program does its steps (run time). Rust is strict at the first moment so that very little goes wrong at the second. If something in your text does not make sense, the compiler tells you before the program ever starts. You will see that in a few minutes, and by the end of the course you will like it.
What we are building
Over the course you will build one program, a small chat client called Chatterbox. It runs in a terminal and, by the last chapter, talks to a real AI model. Each lesson teaches one idea and ends with that idea added to Chatterbox, so you learn Rust by using it.
This is a mock-up of the finished thing, so you know where we are heading. It is not real yet:
$ cargo run
Chatterbox v1.0 (type /quit to leave)
what is Rust good at?
bot> Programs that need to be fast and not crash: servers, tools, and the parts of AI systems that move a lot of data.
/quitSay it out loud, then reveal
In one sentence, what is a program?Reveal
What does fn main() mark?Reveal
What is the difference between compiling and running?Reveal
That is lesson 1.1. Tick it off so the course remembers where you are.
Sources The Rust Book: Hello, World!