►
Description
A Tale of Teaching Rust by Andrew Brinker
Rust has a reputation of having a very steep learning curve, but is this reputation justified? In this talk I share my experiences teaching Rust to a group of 26 undergraduates as part of a class on programming language theory. None of the students knew Rust going in. Most knew only one language. I walk through the key concepts from Rust that programmers in all languages can use, and that language designers may want to steal, and I talk about how this class of fledgling programmers handled and understood those concepts, what they think of Rust now, and what all of this might mean for teaching Rust effectively in the future.
A
They
basically
have
an
extra
section
and
they
needed
someone
to
cover
it
and
asked
me
if
I
would
do
it
and
I
said
sure
now
normally
the
class
is
done
with
so
it's
four
languages,
usually
Lisp
C,
Java
and
Prolog
and
I
decided
okay.
Well,
let's,
let's
replace
the
C
with
rust,
because
it's
2017
and
the
class
has
been
around
for
decades
and
C
is
fine
but
wanted
to
replace
it
with
rust
cuz.
You
know
why
not,
but
then
there's
the
question
of
how
are
we
actually
going
to
do
that?
A
So
three
weeks
for
us
totals
three
three
to
two.
There
is
absolutely
no
time
to
teach
a
bunch
of
students
rust
with
like
a
couple
hours
a
week
across
three
weeks.
So
then,
how
do
you
actually
do
it?
Well,
you
have
to
figure
out
what
is
rusts
pitch.
What
is
the
what?
What
are
the
things
about
rust
that
other
languages
don't
do
can't
do?
What
are
the
interesting
things
where,
if
you're
introducing
rust,
just
someone
brand
new
that
you
would
focus
on
so
probably
all
seen
this
list
or
something
like
it?
A
This
is
basically
a
slightly
modified
version
of
the
list
you
find
on
the
rust
website.
Homepage
of
just
like
here,
the
cool
things
about
rust,
and
so
from
this
list,
I
picked
three
things:
guaranteed
memory,
safety
without
garbage
collection,
threads
without
data
races
and
optional
unsafety.
So
that
means
week
one
is
safety
without
garbage
collection,
which
is
basically
ownership,
borrowing
and
lifetimes
week.
A
Two
is
threads
without
data
races,
so
we,
which
is
basically
everything
in
week,
one
talking
about,
send
and
sync,
and
basically
how
concurrency
and
parallelism
works
and
how
rust
ensures
safety
there
and
then
week
three
kind
of
explain
why
all
of
it
matters.
So
what's
the
plan?
That's
sort
of
the
the
brief,
but
then
what's
the
actual
plan,
the
class
is
a
fairly
small
class.
Twenty
six
upper
division
undergrads.
These
are
like
juniors
and
seniors
a
whole
bunch
of
backgrounds.
Some
of
them
have
been
programming
since
they
were
like
in
their
cribs.
A
A
So
what's
the
approach,
how
do
you
actually
get
people
who
are
if
either
not
sure
of
or
you
know
best
iffy
about
rust
interested?
So
the
first
thing
for
me
was
to
be
really
concrete.
There's.
This
is
definitely
a
mistake.
I
made
with
Haskell
was
diving
into
the
sort
of
abstract
nonsense
a
little
too
quickly.
You
want
to
I
say
this
is
someone
who
loves
the
abstract
nonsense
it
can
be
challenging
for
for
new
people
and
for
newer
programmers.
So
you
want
to
be
really
concrete
want
to
provide
lots
of
examples
live
coding.
A
A
lot
of
the
class
was
actually
structured
as
sort
of
a
question
and
answer
type
thing.
So
I
would
I
had
some
examples
that
I
would
prepare
and
then
sort
of
work
through
them
and
the
students
had
questions
would
sort
of
say.
Oh,
let's
find
out
live
code
and
work
through
the
answers.
Now
this
requires
that
whoever
is
doing
it
or
the
teacher
it
requires
you
to
know
rust
well
and
be
able
to
kind
of
roll
with
the
punches
too.
A
A
Also,
rust
C
can
actually
be
a
really
fantastic
teacher
because
of
all
of
the
work
that
has
gone
into
error
messages,
they're
actually
really
nice
now
and
you
can
use
them
as
a
teaching
aid,
which
is
definitely
something
that
I
did
just
also
a
note,
if
you
don't
know
something
and
you're
trying
to
teach
people.
This
is
true
of
rust
or
just
anything
else,
don't
fake
it
don't
try
to
guess
at
why.
A
Something
is
the
way
it
is
say,
I,
don't
know
and
come
back
to
it,
because
the
worst
thing
you
can
do
is
give
a
incorrect
answer.
That
gives
them
a
bad
mental
and
mental
model
or
understanding
of
what's
happening,
and
then
they
have
to
sort
of
unlearn
it
later.
It's
also
helpful
to
know
the
ecosystem
of
tools.
Rust
has
a
ton
of
fantastic
tools
that
can
be
used
for
learning.
There's
a
sort
of
a
collection
of
some
of
them
that
I
used
the
playground
is
great
students
really
like
that.
A
The
rust
book,
particularly
the
new
edition
of
the
rust
book,
has
tons
of
fantastic
stuff
I,
put
a
little
heart
next
to
rustlings,
because
I
really
liked.
That
was,
if
you're
unfamiliar
that's.
Basically,
they
are
a
collection
of
short
little
programming
problems
in
rust,
which
is
that
are
collected
and
sort
of
topics
to
teach
a
particular
idea,
and
then
there's
the
the
god
bolt
compiler.
So
that's
basically
a
system
that
allows
you
to
very
easily
look
at
the
assembly
output
of
various
languages.
It
was
traditionally
with
C
or
C++.
A
It
works
with
rust
now
and
that's
super
awesome,
and
then
also
you
want
to
give
the
students
room
to
explore
what
those
tools
do
not
like
the
class
was
definitely
kind
of
freeform.
Students
were
encouraged
to
play
around
and
ask
questions,
and
that
gets
us
to
the
actual
class
so
lab
one
safety
without
garbage
collection
start
out.
Obviously
you
just
hang
you
get
down.
What
are
the
rules
at
hand
here?
So
all
data
has
an
owner.
Ownership
can
be
moved
around
and
you
give
examples
for
that.
A
The
old
owner
can't
use
the
data,
and
then
you
talked
about
the
idea
that
simple
types
can
be
copied.
This
should
all
be
sort
of
easy
and
known
form.
Anyone
who's
worked
with
rust.
You
sort
of
work
through
this,
and
you
have
them,
do
increasingly
complicated
programming
examples
with
it
and
they
realize
that
if
this
is
all
you
have,
it
stinks
like.
If
all
you
have
is
ownership
and
you
can't
do
borrows
or
anything
else,
it's
complete
pain
students
realize
it's
painful
to
work
around,
and
so
then
you
introduce
barns
and
so
for
Barros.
A
This
is
the
the
idea.
This
is
what
this
is.
I've
found.
The
clearest
way
to
explain
it
most
students
got
was
basically
that
you
can
either
have
aliasing
or
mutability,
but
not
both
once
again
emphasize
the
rules
give
lots
of
example.
They
lots
of
examples
and
show
complex
cases.
You
want
to
really
work
through
it
and
put
in
the
effort
to
make
sure
that
their
understanding
of
it
is
solid
before
you
move
on,
because
otherwise
students
can
get
really
lost,
and
this
is
a
thing
I've
seen
with
like
newer
programmers.
A
They
try
to
like
not
read
the
rust
book
and
I
try
to
kind
of
just
jump
in
and
start
writing
stuff,
I'm
sure.
You've
all
seen,
questions
or
people
are
like
I
tried
to
write
a
doubly-linked
list
in
rust
and
it
doesn't
work.
Why
does
rust
stink
and
the
answer
is
well?
Okay,
there's
a
lot
of
stuff!
You've
got
to
do
first,
because
it's
not
as
easy
as
you
necessarily
thought
doing
it
in
sort
of
this
constructive,
very
structured
way.
I
found
is
really
the
way
to
go,
and
then
students
generally
will
ask
ok.
Well.
A
How
does
this
work?
How
is
it
actually
verifying
that
everything
I'm
doing
is
safe,
because
this
still
seems
like
magic
a
little
bit?
And
so
that's
when
you
introduce
lifetimes,
and
so
actually
this
next
one,
it
will
no
longer
be
true
with
non
lexical,
lexical
lifetimes,
but
obviously
non
lexical
lifetimes
are
not
yet
here
and
so
for
my
teaching.
This
is
what
I
taught
basically
that
lifetimes
are
scopes
and
that
all
the
borrows
have
them.
So,
whether
they're,
explicit
or
not,
everything
has
one.
A
It's
there,
whether
you
don't
you
don't
have
to
necessarily
know
about
it
and
the
compiler
is
tracking
them
that
it's
it's
not
like
when
you
make
it
explicit
that
it's
suddenly
born
from
the
ether
was
there
already
I'm,
also
made
clear
you
can't
assign
a
lifetime.
You
can't
just
arbitrarily
say
like
this
thing.
Has
this
lifetime
that
it
not
its
scope
like?
No,
that's,
not.
Students
would
try
to
write
code
like
that
and
then
there's
that
last
okay.
A
Well,
what's
up
with
like
instructs
that
you
have
these
these
lifetimes
or
when
you
have
functions
that
are
generic
over
lifetimes.
What's
up
with
that,
and
so
you
talk
about
okay.
Well,
you
can
have
code,
that's
generic
over
lifetimes
and
your
lifetimes
can
have
constraints
and
once
again
it's
very
sort
of
structured
lots
of
examples.
Everything
should
be
kind
of
building
on
each
other
and
that's
when
and
you'd
say
that.
A
Okay,
when
these
situations,
that's
when
you
make
lifetimes
explicit
and
if
you
have
time
I
didn't
because
once
again
it
was
a
basically
three
weeks
with
rust
and
that's
like
class
twice
a
week,
I
think
it's
a
good
idea
to
try
to
introduce
cell
and
ref
cell.
Just
if
or
not
no
other
reason,
then
they
shouldn't
seem
like
magic.
A
They
can
seem
like
magic,
sometimes
if
you're
not
familiar
with
help
with
what
they
are,
why
they
exist,
how
they
work
and
so
I
think
introducing
them
is
worthwhile,
and
so
the
assignment
for
this
class
was
actually
to
do
the
move,
semantics
rustlings
exercises.
This
is
a
great
thing.
Is
why
I'm
very
happy
this
sort
of
stuff
exists?
Other
people
have
done
lots
of
work,
but
that
I
can
just
borrow
for
lessons
which
is
always
nice.
A
So
the
move-
semantics
rustlings
exercises
are
basically
just
a
collection
of
these
programming
problems
that
guide
you
through
and
sort
of
test
you
on
understanding
these
topics
of
ownership
and
borrowing
and
life
times,
and
so
that's
week,
1
week,
2
threads
without
data
races.
So
basically
this
is
you
know
how
does
rust
achieve
once
again.
This
thing
that
can
seem
like
magic.
A
lot
of
this
really
is
demystifying
the
magic
so
start
with
definitions.
This
is
a
thing.
A
People
I
found
pretty
Glee
within
the
new
students
who
are
new
to
computing
in
general,
don't
Sara,
Lee
know
all
of
the
terminology
of
concurrent
and
parallel
programming,
and
so
you
want
to
you
know:
I'm,
not
gonna,
read
all
these,
but
just
sort
of
these
sorts
of
definitions,
things
you
want
to
get
down.
What
are
data
races,
race
conditions,
concurrency
parallelism,
so
on
same
as
before
the
super
concrete?
A
Also,
rust
has
super
cool
stuff
in
this
this
world.
With
these
sort
of
easy
parallelism
things,
these
are
some
some
libraries
that
you
can
sort
of
show
off
and
be
like
look
at
how
easy
this
is
to
make
take
a
for
loop
and
make
it
parallel.
Or
you
know
whatever
it
is
you
wanting
to
do.
These
are
sort
of
fun
things
to
show
how
good
it
is
and
sort
of
justify
why
we
like
having
safe
and
easy
concurrency
and
parallelism,
and
then
so
the
assignment
was
to
solve
the
dining
philosophers
problem
if
you're
unfamiliar.
A
Basically,
it's
a
classic
problem
in
parallel
computing
you've
got
a
table
with
a
bunch
of
plates
of
food
and
forks
and
philosophers
sitting
at
with
each
of
the
plates
of
food,
and
the
philosophers
will
only
eat
when
they
can
pick
up
both
forks
and
the
forks
are
shared,
and
you
have
to
figure
out
some
way
to
make
sure
that
all
the
philosophers
eat.
No
one
starts
to
death,
and
it
turns
out
that
this
is
actually
is
challenging.
A
A
And
they
turned
that
end
up
like
okay,
great,
that
I'm
glad
you
got
this
to
compile
and
that's
you
know
great,
but
this
is
this
is
not
the
problem
ants.
You
have
to
kind
of
walk
through
that
a
little
bit,
and
so
then
that
takes
you
into
week
three
safety
and
security,
so
this
is
kind
of
a
bold
move.
Third
week
of
them
seeing
and
working
with
rust
at
all
introduced
unsafe
this,
this
may
seem
crazy.
A
So,
first
you
want
to
explain
the
notion
of
safe,
rust
and
unsafe
rust
and
almost
that
they
are
not
different
languages,
but
that
you
have
to
sort
of
view
them
distinctly
I.
Think
it's
also
useful
to
talk
about
unsafe
tea
in
in
sort
of
this
split
context,
you
have
unsafe
functions
and
unsafe
traits,
which
are
basically
things
that
have
requirements.
A
The
compiler
can't
check
and
the
programmer
basically
has
to
check
them
and
said
programmer
being
the
user
of
the
functions
or
the
traits,
and
so
that's
basically
establishing
like
hey,
there's
some
requirement
here
and
then
you
have
unsafe
blocks
and
unsafe
trait
implementations,
which
are
the
other
side
of
it.
Basically,
your
the
compiler,
hey,
I've,
checked
these
and
the
compiler
says
that
okay-
and
just
you
know,
goes
from
there
safe
rust
has
to
trust
unsafe
rust.
A
Think
the
example
that
the
rust
and
nomicon
gives
is
of
a
piece
of
unsafe
code
that
uses
the
Ord
implementation
of
some
types
of
its
implementation
of
the
ordering
treat
and
basically
relies
on
that
ordering
being
sensible.
Then
you
can't
do
that
because
the
Ord
is
a
safe,
trait
and
you.
It
should
never
be
the
case
that
safe
code
from
another
module
outside
the
boundary
can
induce
unsafe
T,
and
this,
of
course,
then
connects
the
idea.
A
Safety
lies
at
the
module
boundary
and
you
want
to
make
that
clear
and
that's
really
just
a
consequence
of
rusts
privacy
rules.
Now
the
reason
I
sort
of
think
it's
useful
to
bring
all
this
up.
I
work
in
cybersecurity
as
like
my
day.
Job
and
safety
has
an
impact
on
security,
and
there
are
a
lot
of
context
right
now,
so
you
have
like
C
or
C++,
which
don't
necessarily
provide
the
same
safety
mechanisms
and
and
they're
used
in
environments.
That
obviously
are
may
be
embedded
can't
tolerate
a
garbage
collection.
A
You
have
different
places
where
these
languages
are
still
used.
We
have
lots
of
old
existing
code,
that's
in
C
or
C++,
and
we
have
a
lot
of
these
Commons
sorts
of
vulnerabilities
that
we've
known
about
for
a
long
time
that
still
get
written
and
discovered
and
cause
lots
of
problems,
and
so
the
assignment
for
students
for
this
week
was
actually
to
find
a
CV
that
could
have
been
stopped
by
rust.
A
So
if
you're
not
familiar,
the
CVE
lists
the
common
vulnerabilities
and
exposures
list,
it's
basically
a
disclosure
list
for
vulnerabilities
in
common
and
popular
software,
and
so
I
basically
gave
them
the
the
definition
that
rust
uses
for
what
is
considered
unsafe,
hater
and
said,
find
something
in
this
list
and
then
find
a
vulnerability
in
the
CVE
list.
That
is,
of
this
type
right.
So
a
buffer
overflow.
A
Maybe
if
you
talked
about
Reich
rust,
dealing
with
panicking
a
buffer
overflows
or
if
you
want
to
talk
about
use
after
free
and
some
CVE
that
was
related
to
it,
use
after
free
error
and
so
I,
basically
set
them
loose
on
the
CVE
list
and
said,
come
back
to
me
with
a
CDE
and
a
little
explanation
of
what's
going
on
and
how
rust
couldn't
would
have
stopped
it,
and
this
I
think
connects
to
this
idea.
There
there's
been
so
been
a
suggestion.
A
I
guess
that
that
rust
should,
in
terms
of
marketing
or
like
selling
rust,
move
a
little
bit
away
from
pushing
safety,
because
lots
of
people
aren't
interested
and
I
totally
get
that
perspective.
But
my
feeling
really
is
that
the
safety
is.
Is
the
big
deal,
the
fact
that
we
can
have
this
code?
You
can
write
code
that
works
in
the
context
where
C
and
C++
are
used,
but
that
doesn't
have
these
same
sorts
of
problems.
I
think
that's
a
really
big
deal
and
I
wanted
to
sort
of
illustrate
why
you
should
care
about
safety.
A
A
The
compiler
can
be
a
real
pain.
You
know
you
solve
one
problem
and
you
know
the
another
problem
pops
up
and
it
turns
out
that
you're
thinking
about
the
whole
thing
wrong
and
have
to
do
some
big
restructuring
as
you
sort
of
get
used
to
the
way
that
rust
requires
you
to
think.
Also.
The
syntax
was
weird.
Students
were
mostly
used
to
C
or
C++,
and
rust
is
sort
of
this
hybrid
of
C
and
C++,
but
also
like
taking
things
from
the
the
ML
world.
A
A
A
But
but
don't
despair
there
that
there
were
good
things.
I
said
to
most
of
the
students
wanted
to
try
rust
more
after
it
was
done
right,
there's
only
three
weeks,
not
a
ton
of
time,
but
a
number
of
students
indicated
some
interest
or
preference
to
continue
working
in
rest.
Students
also
felt
that
rust
was
really
powerful.
I
think
this
is
the
the
really
great
thing.
I
know
this.
A
By
the
same
token,
students
felt
more
confident
with
rust
and
they
did
with
C++,
and
that
was
something
that
I
was
certainly
very
happy
with
and
I
think
that
there
are
even
more
reasons
for
optimism.
The
ergonomics
initiative
will
really
help
new
restorations
a
lot
of
the
stuff
that
was
discussed
actually.
A
Just
in
the
last
talk
about
the
ergonomic
improvements
being
made
to
the
language
directly
address
a
lot
of
the
pain
points
that
my
students
came
to
me
with,
and
so
that's
really
encouraging
and
I
think
that
that
will
make
introducing
rust
to
new
programmers,
introducing
rust
and
general
think
just
a
lot
better.
Also,
this
one
actually
surprised
me:
students
did
a
lot
better
with
ownership/borrowing
and
lifetimes
than
I
expected
and
I
wonder
if
this
is
just
because
they
were
that
most
of
them
were
newer.
A
So
in
conclusion,
can
rust
be
taught
in
three
weeks?
No,
but
but
you
can't
get
students
excited
and
interested
and
get
get
them
wanting
to
try
it.
Some
more
can
rust
be
taught
to
newer
programmers.
Absolutely
I
I
was
really
pleased
with
how
they
did
and
and
with
the
the
ease
with
which
they
approached
some
things,
which
I
really
expected.
They
were
going
to
find
harder
than
they
did
and
can
rust
overcome
the
bad
press
on
its
learning
curve.
A
I
think
so
remember
mostly,
students
came
most,
but
number
of
the
students
came
in
having
only
heard
that
rust
was
hard
and
scary
and
in
thinking
of
basically
that
they
didn't
want
to
do
it
and
by
the
end
those
students
were
pretty
much
universally
either
like
okay,
on
rust,
like
with
rust
or
excited
and
interested
in
programming
and
rust.
More
so,
thank
you
very
much.