Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
A Tale of Teaching Rust
Search
Andrew Lilley Brinker
April 10, 2025
Programming
0
15
A Tale of Teaching Rust
Andrew Lilley Brinker
April 10, 2025
Tweet
Share
More Decks by Andrew Lilley Brinker
See All by Andrew Lilley Brinker
Memory Safety and the Future of Vulnerabilities
alilleybrinker
0
25
Hello and Welcome: Documentation in the Rust Ecosystem
alilleybrinker
0
13
Efficient Nimber Calculation in Dots and Boxes
alilleybrinker
0
99
Other Decks in Programming
See All in Programming
Catch Up: Go Style Guide Update
andpad
0
210
XP, Testing and ninja testing ZOZ5
m_seki
3
600
明日から始めるリファクタリング
ryounasso
0
130
2分台で1500examples完走!爆速CIを支える環境構築術 - Kaigi on Rails 2025
falcon8823
3
3.5k
いま中途半端なSwift 6対応をするより、Default ActorやApproachable Concurrencyを有効にしてからでいいんじゃない?
yimajo
2
400
uniqueパッケージの内部実装を支えるweak pointerの話
magavel
0
970
CSC509 Lecture 05
javiergs
PRO
0
300
オープンソースソフトウェアへの解像度🔬
utam0k
12
2.5k
ソフトウェア設計の実践的な考え方
masuda220
PRO
4
550
Back to the Future: Let me tell you about the ACP protocol
terhechte
0
140
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
210
Server Side Kotlin Meetup vol.16: 内部動作を理解して ハイパフォーマンスなサーバサイド Kotlin アプリケーションを書こう
ternbusty
2
130
Featured
See All Featured
Scaling GitHub
holman
463
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
Optimizing for Happiness
mojombo
379
70k
Thoughts on Productivity
jonyablonski
70
4.9k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Practical Orchestrator
shlominoach
190
11k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Become a Pro
speakerdeck
PRO
29
5.5k
Testing 201, or: Great Expectations
jmmastey
45
7.7k
Transcript
A Tale of Teaching Rust Andrew Brinker
Hi! I’m Andrew!
I’m here to tell you a story
Act 1: The Idea
In early 2017, I was asked to teach a class
on programming languages
I replaced C with Rust, because it’s 2017
10 weeks long. Enough time for Rust, right?
Normally: Lisp, C, Java, Prolog Me: Haskell, Rust, Java, Prolog
3 weeks for Rust. No time to teach it all!
Act 2: The Pitch
What is Rust’s elevator pitch?
Zero-cost abstractions Move semantics Guaranteed memory safety (without GC) Threads
without data races Trait-based generics Type inference Minimal runtime Optional unsafety And more!
Zero-cost abstractions Move semantics Guaranteed memory safety (without GC) Threads
without data races Trait-based generics Type inference Minimal runtime Optional unsafety And more!
Week 1: Safety without GC = Ownership + borrows
+ lifetimes
Week 2: Threads without data races = Week 1
+ Send + Sync
Week 3: Explain why it matters
Act 3: The Plan
26 upper-division undergrads Wide variety of backgrounds None knew Rust
going in Some heard Rust was hard
What’s the approach?
Be very concrete: Lots of examples Live coding
Potential challenge: this requires the teacher to know Rust well
Suggestions: 1. Do examples beforehand 2. Treat rustc as a
teacher 3. Don’t fake it
Know the ecosystem of tools
Rust Playground The (New) Rust Book Rustlings ❤ Godbolt
Give room & tools to explore
Act 4: The Class
Lab 1: Safety without GC
All data has an owner Ownership can be moved Old
owner can’t use data Simple types can be copied
Students will realize this is painful to work around
Then introduce borrows
Aliasing XOR Mutability
Emphasize the rules Give lots of examples Show some complex
cases
Students will ask how it works
Then introduce lifetimes
Be very explicit: lifetimes are scopes, and all borrows have
one
The compiler tracks them whether they’re explicit or not
You can’t assign a lifetime
Sometimes you need code that’s generic over lifetimes
That’s when you make lifetimes explicit
If you have time (I didn’t), introduce Cell & RefCell
Assignment: do the move semantics Rustlings exercises
Lab 2: Threads w/out data races
Start with de fi nitions
Concurrency: Multiple threads of control Parallelism: Multiple threads of control,
running at once Deadlock: All threads are stopped (dead) Livelock: Threads are live, but not progressing Data race: Non-syncing mutable data across threads Race condition: Result depends on execution order And so on…
Same as before, be concrete
Talk about Send and Sync
Explain why some types implement them, and some don’t
Don’t explain unsafe traits (yet)
Introduce the key stdlib types: Arc, Rc, Mutex, RwLock
Explain why Arc is Sync but Rc isn’t
Make clear that Rust stops data races, not race conditions
Easy parallelism is the best! Show it off! Rayon, Hyper
w/ Tokio, Crossbeam
Assignment: solve the Dining Philosophers problem
Lab 3: Safety & Security
Bold move: Introduce unsafe
Explain Safe Rust & Unsafe Rust
Unsafe functions + unsafe traits: Have requirements the compiler can’t
check The programmer has to check instead
Unsafe blocks + unsafe trait impls: Tell the compiler “I’ve
checked these!” The compiler assumes you did so correctly
Safe Rust must trust Unsafe Rust
Unsafe Rust can’t trust Safe Rust
Safety lies at the module boundary
Safety has an impact on security
Embedded environments often can’t tolerate GC
Lots of old code in C and C++
Lots of common vulns still being written
Assignment: fi nd a CVE that could have been stopped
by Rust
Act 5: The Results
Ended the series with a post-Rust survey
Here’s what my students said:
Students thought the compiler was too picky
And the syntax was weird
A couple said they only liked Rust in comparison to
Haskell, which was too weird
Don’t despair!
Most students wanted to try Rust some more!
Students felt Rust was really powerful
Students felt more con fi dent than they did with
C++
And there are more reasons for optimism
The ergonomics initiative will help new Rustaceans!
Students did way better with ownership, borrowing, and lifetimes than
expected!
Conclusion
Can Rust be taught in 3 weeks? Not quite, but
you can get students excited for more!
Can Rust be taught to newer programmers? You bet!
Can Rust overcome the bad press on its learning curve?
I sure think so!
Thank you very much!
Twitter: @AndrewBrinker Github: @AndrewBrinker Class site: proglangs.com My site: andrewbrinker.com