►
From YouTube: GoGaRuCo 2014- Let’s Talk About Rust
Description
By, Yehuda Katz
Help us caption & translate this video!
http://amara.org/v/FUGR/
A
So
30
minutes
is
a
really
aggressive
timeframe
to
introduce
a
group
of
people
that
doesn't
really
have
much
context
for
this,
so
I'm
gonna
maybe
go
a
little
fast,
maybe
hopefully
not
too
fast,
but
also
there's
a
you
should
think
of
this
talk
as
a
starting
off
point,
a
jumping-off
point
for
your
in
interest
in
rust.
If
you
become
interested-
and
maybe
there
will
be
a
few
things
here
and
there
that
you
could
sort
of
jump
off
and
use
or
look
into
I'm
gonna,
be
writing
a
blog
post
over
the
next
few
weeks.
A
I
think
that
talks
about
how
you
specifically
integrate
rust
into
a
Ruby
or
rails
application
and
I'm
not
gonna,
talk
about
that
today,
because
that's
kind
of
its
whole
other
talk
but
I.
Think
if
you
really,
if
you
leave
this
talk,
thinking
that
you
really
want
to
use
rust
for
something
real,
that's
probably
gonna
be
the
best
way
for
you
to
do
that,
so
keep
an
eye
out
for
on
the
skylight
blog
we'll
be
talking
about
it
yeah.
What's
up
with
that.
A
So
I
think
the
way
a
lot
of
people
look
at
programming
languages
is
with
this
sort
of
quadrant
grid.
You
can
see
that
when
they
announce
Swift
Apple
created
this
quadrant
grid
and
among
despite
the
fact
that
it's
really
silly
like
I,
don't
think
Ruby
is
faster
and
more
performant
and
more
performant
than
JavaScript
and
I.
Don't
really
I,
don't
understand
any
of
it
really,
but
I
think
people
do
think
of
the
world
in
terms
of
these
quadrants
and
I.
Think
if
I
was
gonna,
give
a
talk
about
rust
and
I.
A
The
only
constant
is
change,
and
what
that
means
is
that
a
lot
of
people
have
this
fixed
picture
in
their
head
of
this
trade-off
between
performance
and
productivity,
and
they
imagine
that
that
trade-off
is
kind
of
fixed.
So
if
you
gain
a
little
more
productivity,
then
surely
what
that
means
is
that
you've
traded
off
some
performance.
A
But
if
you
look
at
reality,
you
look
at
reality,
and
this
is
let's
say:
2005
you'll
see:
okay,
there's
the
programming
language
JavaScript,
which
didn't
have
that
logo.
At
the
time
it
was
a
reasonably
productive
programming
language.
It
was
a
dynamic
language.
Maíam
does
not
very
fast
and
then,
if
you
were
gonna,
look
at
that
diagram
and
fast
forward
10
years,
obviously
javascript
hasn't
improved.
It's.
A
It
hasn't
really
changed
that
much
in
terms
of
productivity.
It
hasn't
gotten,
maybe
it's
gotten
a
little
bit
better,
but
for
the
most
part,
the
language
that
most
people
write
today
is
the
same
language.
The
most
people
wrote
ten
years
ago.
So
if
you
were
gonna
think
about
things
as
just
a
trade-off
between
productivity
and
performance,
you
would
expect
well,
of
course,
JavaScript
hasn't
gotten
any
hasn't
become.
Worse
than
productivity,
so
that
means
it
must
not
have
gotten
faster.
A
It
enables
a
whole
new
generation
of
people
to
do
something
that
they
couldn't
do
before
and
I
think
you
javascript
is
really
good
example.
This
right
JavaScript
was
really
a
slow
language
to
begin
with,
but
when
JavaScript
got
fast
and
when
it
got
a
little
more
productive
and
when
the
ergonomics
of
using
it
on
the
server
got
better,
it
enabled
a
whole
generation
of
front-end
developers
to
write
back-end
code
and
I.
Think
you
could,
you
could
say:
oh
well,
I
don't
want
my
jQuery
developer,
writing
back-end
code.
A
You
can
say
that
all
you
want,
but
the
reality
is
that,
if
you're
looking
at
the
quadrant,
you
missed
these
shifts
these
changes
in
the
programming
landscape
that
enables
whole
generations
of
people
large
groups
of
people
to
do
something
that
they
weren't
able
to
do
before
and
rust
is
sort
of
trying
to
do
a
similar
thing
right.
So
Russ
is
a
new
language,
but
rust
is
also
trying
to
enable
people
who
might
not
have
been
willing
to
do
something
before
or
might
not
be
able
to
do
something
for
it
to
do
something.
A
Now
and
just
to
give
you
a
high-level
sense
of
what's
going
on
here
before
Russ,
there
were
essentially
two
kinds
of
languages:
there
were
languages
that
were
safe
and
what
I
mean
by
safe
is
that
if
you
write
a
program
in
the
programming
language
and
there's
no
bugs
in
the
compiler
or
the
interpreter,
your
program
cannot
have
a
seg
fault
right.
So
whenever
that
happens
to
you
in
Ruby,
what
that
means
is
that
there's
some
C
code
involved.
A
It's
not
Ruby
giving
you
the
seg
fault,
it's
some
C
code,
giving
it
a
seg
fault
and
that's
a
guarantee
if
you
write
in
Ruby
or
you
write
in
Python.
You're
writing
go
because
there's
a
garbage
collector
in
those
programming
languages
you're
guaranteed
that
if
you
write
code
will
not
get
a
seg
fault
and
then
there's
other
languages,
C
C++
and
a
few
other
languages
of
that
oak.
A
That
give
you
direct
control
over
where
you
can
put
your
memory
and
that
correct
control
gives
you
the
ability
to
get
better
performance,
better
memory
usage
and
all
that.
But
the
trade-off
of
that
is
that
if
you
make
a
little
mistake,
if
you
slip
up
a
little
bit
and
everybody
knows,
who's
ever
tried
to
work
with
C
or
C++
that
it's
not
just
a
matter
of
learning
these
five
tricks.
A
That
could
mean
putting
things
on
the
stack
or
a
variety
of
other
places
where
you
might
want
to
allocate
memory.
You
have
direct
control
over
that,
but
you
don't
have
to
trade
off
safety
and
I.
Think
from
from
an
ergonomics
perspective,
if
you
are
a
person
that
has
ever
tried
to
write
code,
that's
more
efficient
by
having
more
control
the
biggest
source
of
ergonomic
pain,
the
biggest
source
of
productivity
is,
is
not
just
that
you
lose
all
these
high-level
features.
A
It's
also
that,
at
any
point
you
could
crash
so
just
eliminating
the
ability
to
ever
crash
really
is
a
big
shift
in
the
landscape
of
of
what's
possible.
So
what
is
this
enable?
What
does
it
mean
so,
like
I
said
before,
I
think
the
way
you
should
always
look
at
the
programming
landscape
is
looking
for
shifts
for
changes
in
what
some
language
is
doing
what's
possible?
What
does
it
mean
to
have
a
language
that
is
both
low
level
and
direct
memory
controlled,
but
also
safe?
A
What
is
that
enable
for
us
and
what
it
enables
is
a
whole
new
generation
of
people
who
are
systems
programmers
and
by
that
I
mean
you,
everyone
in
this
room.
It
enables
every
people
who
maybe
would
have
been
excited
or
interested
in
low
level
systems
programming
to
do
it
and
no
js',
which
claims
to
be
low
low
to
the
metal.
That's
not
what
I
mean
when
I
say
systems.
Programming
I,
don't
mean
you
know.
A
Programming
on
the
metal
in
node.js
I
mean
really
really
programming
on
the
metal
really
programming
at
the
level
of
the
machine,
so
before
I
continue.
I
want
to
just
throw
out
some
real
talk
here
and
that's
to
say
that
all
of
us
in
this
room,
including
myself,
have
been
part
of
the
high
level
language
tribe.
We
spend
a
lot
of
time
talking
to
ourselves
and
each
other
about
why
we
find
ourselves
being
productive
in
high-level
languages
and
a
big
part
of
the
high-level
language.
A
A
Think
that's
a
thing
that
we
tell
each
other
a
lot
and
I
think
that
in
many
many
cases,
maybe
perhaps
most
cases
that
ends
up
being
true,
but
sometimes
there
are
some
cases
where
you
actually
do
need
better
performance
and
I'll.
Give
you
some
examples
of
this,
so
one
example
is
any
time
anybody
ever
says:
60,
FPS
or
jank,
or
real-time
or
high
frequency
trading,
or
anything
like
that.
Any
time
anybody
ever
talks
about
needing
predictable
performance.
I
think
60fps
is
a
good
example.
A
They
need
better
control
than
you
get
with
a
garbage
collector
any
time
anybody
ever
says,
I
need
to
use
less
memory.
That
memory
is
too
high
if
you're
writing
a
cross-platform,
a
cross-platform
library
like
a
like
libsass,
something
that
is
meant
to
be
embedded
in
a
lot
of
different
places.
That's
a
place
where
you
care
about
performance
and
and,
more
importantly,
whenever
you're
starting
to
dig
into
your
programming
language
internals
whenever
you're
reading
the
Ruby
C
code
or
trying
to
understand
the
JavaScript
JIT.
A
A
I
have
a
couple
examples
from
ember
which
in
JavaScript
there's
very,
very
good
jits,
but
those
very,
very
good
jits
are
very
opaque.
But
when
you're,
when
you
end
up
caring
about
performance,
you
end
up
really
trying
to
understand
how
it
works.
So
here's
an
example
where
we
have
a
function
called
make
dictionary
and
we
do
a
whole
bunch
of
pointless
things
that
are
total
no-ops
in
the
semantics
of
the
language.
But
what
it
does
is
it
tells
the
runtime
to
not.
A
Try
to
compute
this
into
a
struct
and
that
allows
allows
us
to
get
to
avoid
certain
deoptimization
that
you
can
see.
There's
a
big
comment
here:
here's
another
thing:
there's
a
function
called
in
turn,
which
takes
a
string
and
gets
back
an
on
rope
version
of
the
string
and
that
ends
up
having
performance
problems.
To
not
do
it
and
you
can
see
on
top.
It
says
when
do
I
need
this
function
for
the
most
part,
never
premature,
optimization
is
bad,
etc,
etc,
and
here's
the
whole
comment
right.
A
So
it
turns
out
that
when
you
care
about
performance,
we
should
think
about
what
is
the
point
of
a
programming
language.
The
point
of
a
programming
language
is
to
let
us
communicate
with
other
human
beings
about
what
it
is
that
we're
trying
to
do,
and
if
it
turns
out
that
you
don't
care
about
performance,
then
you
don't
want
to
waste
your
time.
Communicating
with
other
human
beings
about
performance
that
becomes
a
waste
of
time.
It
becomes
very
noisy,
becomes
difficult
for
you
to
understand.
A
What's
going
on
in
your
code,
but
as
Dave
Herman
who
founded
mozilla
research,
says
when
you
actually
do
care
about
performance,
then
performance
is
part
of
the
domain
of
discourse
for
you
and
your
collaborators.
You
actually
want
away
in
the
programming
language
to
explain
the
performance
requirements
that
you
actually
have.
A
Remember
usage
has
really
impact
like
skylight,
which
is
the
project
I
work
on
that
caused
me
to
get
into
rust
in
the
first
place
and
when
it
matters,
it's
actually
a
blessing
that
you
have.
It's
not
that
I
have
to
write
all
these
annotations.
It's
that
I'm
able
to
communicate
to
Carl
and
Tom
and
all
the
other
programmers
who
I'm
working
with
exactly
what
performance
requirements
we
expect
to
have
from
the
program
that
we're
writing.
So
that's
why
you
should
care
about
Rosten
the
kinds
of
cases
you
should
care
about
now.
A
I
want
to
get
into
sort
of
what
is
rust,
so
I
can
spend
a
lot
of
time
talking
about
the
low-level
performance.
I
think
you
can
write,
do
some
benchmarks.
If
you
want
to
look
at
sort
of
all
the
performance
features.
I
want
to
talk
a
little
bit
more,
because
this
is
a
ruby
crowd
about
high-level
productivity
and
before
I
talked
about
productivity.
I
want
to
talk
about
one
really
important
principle
in
rust,
which
is
the
idea
of
zero
cost
abstraction,
which
I
know
sounds
a
little
bit
like
snake
oil.
A
But
the
idea
behind
zero
cost
abstractions
is
that
when
you
add
the
ability
to
do
an
abstraction
in
a
programming
language
in
most
cases,
if
you're,
not
very
careful,
you
end
up
adding
a
little
bit
of
cost
a
little
bit
of
cost
a
little
bit
of
cost.
And
then,
when
you
get
to
something,
that's
abstract
as
rails.
A
Introducing
a
whole
lot
of
cost
and
I
think
this
is
a
big
part
of
what
is
really
appealing
to
me
about
rust,
which
is
that,
even
if
we
didn't
consider
the
safety
aspects
of
writing
in
a
programming
language
like
C
and
of
course,
I,
do
the
fact
that
C
is
so
difficult
to
have
to
write.
Abstractions
in
is
really
also
a
big
problem.
So
I'm
gonna
start
by
looking
at
some
a
program
in
Ruby
that
you
can
look
at
if
you
go
to
active
support
and
that's
the
blank
method
that
exists
on
strings
in
Ruby.
A
So
here's
how
its
implemented
I
just
dragged
this
out
of
active
support
that
you
reopen
the
string
class.
You
specify
blank
regex
and
that's
there
because
performance
reasons
you
don't
want
to
be
putting
it
in
line,
and
then
you
investigate
the
blank
regex
at
runtime
and
then.
Similarly,
we
have
this
method
on
array
which
is
basically
an
alias
for
empty,
and
then
we
have
nil
class
no
class
is
always
considered
blank,
and
then
you
know
there's
more
and
more,
there's
bullying's
and
whatever,
and
this
exact
kind
of
problem.
A
This
exact
kind
of
thing
is
actually
something
that
rust
lets.
You
talk
about
and
I'll
talk,
I'll
show
you
how
that
works
in
Russ,
so
in
Ruby.
Actually,
the
one
I
showed
you
here
is
sort
of
traditionally
how
you
would
do
it
and
that
basically,
globally
opens
up
all
these
objects
and,
as
the
blank
method,
there's
also
a
new
feature
in
Ruby
called
refinements,
which
allows
you
to
do
a
similar
thing,
but
in
a
scoped
way,
and
that's
more
like
how
it
works
in
rust.
So,
first
of
all
in
rust,
when
you
everything
statically
typed.
A
So
if
you
want
to
say
that
there's
a
blank
method,
you
say
that
there's
a
trait
called
is
blank,
and
we
just
make
a
trait
called
is
blank,
and
we
say
that
has
a
function
on
it.
That
function
takes
whatever
you
know,
self,
whatever
it
is,
and
it
returns
a
boolean,
and
the
first
thing
that
we
do
is
we
implement,
is
blank
for
Strings
and
that
ampersand
string
thing
over
there
just
means
that
it's
a
static,
fixed
sized
string.
So
there's
also
strings
that
you
could
push
things
on
to
basically
mutable
strings.
A
This
is
that
symbol.
There
means
immutable
string
that
guy
over
there,
and
this
reg
x
over
here
basically
is
a
macro,
so
anything
with
bang
at
the
end
of
it,
which
is
gonna
change
to
prefix
and
act
soon,
but
anything
with
a
bang
means
macro,
and
that
means
basically
that
it
gets
converted
into
something
fast.
So,
even
though
it's
a
red
X,
it's
not
doesn't
end
up
being
interpreted
every
time,
and
basically,
what
this
is
doing
is
essentially
equivalent
thing
that
we
did
in
Ruby.
We
basically
say
we
have.
A
This
is
blank
trait
and
it
hasn't
his
bike
method,
and
if
it's
a
boolean-
and
here
is
the
implementation
of
it,
you
can
do
similar
things
for
other
types.
So
we've
now
said
I
want
to
implement,
is
blank
for
a
raise
this.
That
basically
also
means
a
fixed
sized
array.
This
little
thing
here,
if
you're
not
familiar
with
other
languages
that
have
types
is
called
a
generic.
A
So
this
is
basically
saying
this
is
implemented
for
an
array
of
any
type,
so
it
doesn't
matter
what
type
it
is
as
long
as
it's
an
array
of
that
type.
It's
what
this
means
over
here,
it's
an
array
of
that
type,
it's
implemented,
and
then
the
actual
implementation
just
says
check
the
length
if
the
length
is
bigger
than
zero.
Actually,
that
should
be
equal,
zero.
A
So
if
the
length
is
zero
its
blank
and
then
we
do
a
similar,
so
rust
also
has
no
null
so
null
is
always
represented
as
a
type
of
option.
So
here
we're
gonna,
say
implement,
is
blank
for
an
option
of
anything
and
the
option
of
anything
is
basically
saying:
okay,
if
it's
none,
which
is
like
the
nil
question,
mark
method
in
Ruby
so
and
then
finally
implement
the
same
thing
for
bool
right.
A
So,
basically
in
this,
in
the
same
way
that
you
can
go
ahead
and
and
implement
things
in
Ruby
for
any
any
type,
even
at
types
you
don't
own,
you
can
basically
make
a
trait
in
rust
and
you
can
implement
it
for
any
type
and
the
way
that
that
gets
used.
As
you
would
say,
something
like
in
use,
activesupport
colon
colon
is
blank
and
then
you
would
be
able
to
use
it.
So
that
is
the
scoping
mechanism.
A
You
have
to
say
where
you
want
to
use
it,
but
once
you've
said
that
you
want
to
use
a
trait
it's
now
imported
into
that
scope
and
you
can
use
it
for
any
method
any
day
object.
So
any
object
that's
implemented,
for
so
we
can
implement
it
for
use
of
restraint,
for
you
know,
arrays
for
boolean
x'
and
then
the
last
one
there
is
I
made
an
array
of
1
and
I
pulled
out
the
last
value
of
it
and
in
rust
that
would
return
an
option
cuz.
A
It
doesn't
have
to
be
something
that
something
the
person
implemented,
the
trait
decided
to
implement
in
the
first
place,
and
so
I
just
showed
you
a
pretty
cool
feature
which
is
basically
it
looks
like.
Oh,
you
know,
dynamic
dispatch,
awesome
everything
is
a
message
etc.
But,
like
I
said
before
in
rust,
everything
is
a
zero
cost
abstraction.
So
how
does
that
actually
work
and
the
way
it
works
in
rust
is
that
rust
actually
knows
when
it
looks
at
those
when
it
looks
at
empty
string
blank
that
is
blank.
A
It
actually
knows
ahead
of
time
exactly
what
method
that's
gonna
be
calling,
and
it
actually
will
statically
dispatch
that
method
to
the
that
method,
to
the
specific
function
that
needs
to
be
called
or
it
might
even
in
line,
and
you
can
explicitly
tell
to
inline
it.
If
you
know
it's
performance,
critical
also
using
traits
doesn't
involve
allocating
anything.
So,
even
though,
in
a
you
know
normal
language,
you
would
basically
be
forced
to
allocate,
because
it's
virtual
dispatch
e
the
dispatching
table
in
rust,
simply
using
a
trade,
doesn't
cause
any
kind
of
special
allocations.
A
It
basically
works.
Just
it
works
fast.
It's
like,
as
if
you
had
written
a
static
method
and
called
it
directly,
even
though
now
it's
basically
polymorphic
now
there's
one
other
thing
that
you
can
do
with
traits.
That's
pretty
awesome.
So
so
far,
I
showed
you
that
you
have
a
you
know.
You
have
an
object
and
you
want
to
call
a
method
on
it
and
you
can.
It
can
be
polymorphic
right
and
now.
A
A
Obviously,
I
could
write
a
first
line
function
and
I
could
make
it
specific
for
standard
in
or
I
could
make
it
specific
for
a
file,
but
what
I
want
to
do
is
I
want
to
make
a
function,
that's
specific
to
any
kind
of
bufferedreader
and
in
Ruby.
Of
course
you
just
do
this
by
saying:
please
implement
the
read
line,
method
and
I'll
call
it
in
rust.
A
Okay,
so
then,
when
I
go
to
call
it
basically,
Rasta
will
mow
okay,
well
you're
calling
first
line,
and
you
can
basically
call
it
with
a
bufferedreader
or
you
can
call
it
standard
in
or
whatever
type
that
you
want.
And
again,
if
you
just
look
at
this,
you
could
imagine
well
I'm
calling
it
with
some
random
thing
and
it
doesn't
know
ahead
of
time.
It's
like
the
function
is
not
written
for
a
specific
type.
So
probably
what
that
means
is
that
it
will
be
super
slow
because
it
will
have
to
be
packaged
up.
A
So
the
idea
is
that
you
get
the
high
level
the
high
level
functionality
that
you
expect
the
productivity
that
you
expect
for
being
able
to
just
say:
I,
don't
really
care
what
this
is.
It's
just
anything
that
takes
a
reader
I'll
just
call
read
line
on
it
and
under
the
hood
what's
happening
is
it
gets
specialized?
It
gets
made
super
fast,
so
another
way
that
this
is
zero
cost
is
that
the
compiler
specializes
any
methods
that
use
trained
what
we've
got,
what
we
call
trait
constraints.
A
A
So
if
you've
written
Ruby
code
or
JavaScript
code,
then
what
you
know
is
that
it's
very
powerful
to
be
able
to
use
blocks
or
lambdas
to
abstract
over
some
kinds
of
things
and
rust
has
a
thing
called
has
lambdas,
but
it
also
has
a
feature
called
iterators,
which
are
you
can
basically
think
of
as
being
the
equivalent
of
lazy
enumerators
in
Ruby,
and
basically
the
idea
here
is
that
you
can
base
to
say:
okay,
give
me
a
range
from
0
to
100
and
then
I'm
gonna
filter
over
it.
By
saying
it's
filtered
by
you
know.
A
Is
it
visible
by
six
and
then
I'm
gonna
map,
if
I'm,
multiplying
by
three
and
then
I'm
gonna
print
it
by
saying
numero
whatever
and
then
run
it
and
there's
so
number
one?
If
you
look
at
this,
it
looks
very
high-level
II.
It
looks
first
of
all,
there's
no
types
which
is
pretty
cool,
but
second
of
all
looks
high-level,
looks
you
know,
you're
using
filter
and
map
and
all
this
stuff.
A
A
It
also
uses
generics
under
the
hood,
like
I
showed
you
before,
which
basically
means
that
every
single
time
you
call
that
map
or
dot
filter,
it's
actually
generating
a
special
version
of
the
code
for
the
thing
that
you're
actually
trying
to
do.
Also
so
one
thing
that
you
have
to
do
whenever
you're
doing
a
loop
in
a
high-level
language.
If
you
want
to
look
up,
you
have
an
array
of
100
items
and
you
say
give
me
the
50th
item
is
that
the
at
best
the
compiler
has
to
say.
A
Let
me
check
to
see
if
the
50th
item
is
there
and
don't
let
you
access
memory,
that's
out
of
the
bounds
of
the
array,
but
if
you
use
something
like
math,
not
only
is
it
a
higher
level
of
abstraction
you're
using
a
lambda,
but
you
could
actually
do
a
single
bounce,
jack
and
say:
okay,
I
can
see
these
50
items.
So
then
you
can
basically
just
do
the
rest
of
the
iteration
without
doing
any
additional
bounce
checks
as
you
go
through
it.
A
So
you
can
get
both
higher
level
of
abstraction
and
faster
performance
at
the
same
time,
which
is
pretty
awesome
and
finally,
rust
actually
doesn't
have
any
C
style
for
loops.
It
only
has
looping
over
it.
It
has
a
raw
loop,
but
other
than
that.
It
only
has
looping
over
iterators
and
that's
because
rust
itself
is
very,
very
confident
in
the
performance
of
iterators
and
the
ability
to
make
those
very
fast
and
an
efficient
and
low
memory
usage.
A
So
I
talked
so
those
are
sort
of
two
high
level
features
and
I
think
you
can
definitely
see
that
if
you
look
at
these
features
that
they're
features
that
you
would
expect
to
have
in
a
productive
language,
but
not
necessarily
in
a
low-level
language.
So
I
talked
about
the
fact
that
this
is
if
this
is
productive.
A
But
I
want
to
show
you
one
kind
of
example
that
I
think
may
help.
You
understand,
number
one.
What's
tricky
and
number
two,
how
Russ
deals
with
it?
So
I
made
a
little
program
here,
which
is
a
ruby
program.
It
has
a
point:
it
inherits
from
structure
the
XY
make
a
line.
The
line
has
length
method
on
it,
and
the
length
is
just
figuring
out
the
length
of
distance
between
two
points.
I
made
a
distance
method
which
takes
two
points,
makes
a
new
line.
P1
and
p2
gets
the
length
and
then
my
count
method.
A
Basically,
I
have
a
count
function
which
is
sort
of
like
main
function
here,
which
basically
will
go,
get
the
distance
and
it
will
return
the
right
value
now.
Let
me
sort
of
trace
through
the
program
what
exactly
is
happening
here.
So
the
first
thing
that
happens
is
I,
make
a
new
point
and
because
this
is
a
garbage
collected
language
because
it's
trying
to
be
safe
and
Ruby
doesn't
really
know
what
else
is
gonna
happen
with
this
point
afterwards,
it's
basically
forced
to
allocate
that
point
on
the
heap.
A
A
The
next
thing
I
do
is
I
call
the
distance
function
and
the
distance
function
also
makes
a
line
object
and
again,
because
the
Ruby
doesn't
really
know
what's
gonna
happen
with
the
line
object,
it
has
to
go
and
put
a
line
somewhere
on
the
heap
and
then
it
goes
and
calls
the
length
method
on
the
line
and
the
length
method
actually
starts
pulling
things
off
of
the
point,
which
is
actually
super
dangerous.
If
you
weren't
garbage
collected
right
because
now
we're
just
pulling
random
things
off
of
this
object.
A
So
we're
really
happy
that
these
things
are
allocated
on
the
heap
because
if
they
weren't
allocated
on
the
heap,
if
they
were
basically
if
they
were
managed
manually,
if
you
were
basically
allocating
them
and
freeing
them-
and
you
start
pulling
random
things
off,
who
knows
what
could
happen?
So
we
basically
go
and
we
pull
a
few
things
off.
We
do
some
calculations,
then
we
call
the
square
root
function
which
is
get
another
function.
A
A
I,
don't
really
know
what's
happening
here,
but
what's
kind
of
interesting
is
that
most
programs
actually
are
written
in
this
way
in
which,
even
though
in
theory,
the
point
object
isn't
sort
of
known
what
it's
doing
in
practice,
it's
being
created,
it's
getting
past
a
bunch
of
functions,
then
it's
getting
returned
and
then
we're
done
with
it
right.
So
in
practice,
what's
happening
is
that
we're
creating
objects?
They
basically
get
used
in
computation.
They
get
returned
right
away,
nobody
hangs
on
to
them.
A
People
aren't
making
threads
and
storing
them
off
or
putting
them
in
other
structures
right.
And
what
and
this
ends
up
meaning
is
that,
even
though,
in
theory
this
is
all
very
simple
and
you
can
sort
of
understand,
statically,
okay,
I
can
just
put
the
memory
in
some
known
location,
pass
it
around,
get
it
back
everything's
great
because
of
the
fact
that
Ruby
doesn't
really
know
it
ends
up
being
forced
to
go
and
do
a
lot
of
extra
memory
work
to
deal
with
the
fact
that
doesn't
really
know
what's
going
on.
A
A
So,
first
of
all,
when
we
say
point
over
here
in
rust,
when
you
say
it
this
way,
when
you
don't
explicitly
allocated
what
you're
saying
is
I
would
like
the
point
to
actually
be
allocated
in
a
known,
fixed
location
that
doesn't
have
to
be
allocated,
and
you
have
to
do
extra
work
to
make
it
be
allocated
somewhere
else.
So
you
make
these
two
points,
and
then
you
call
this
other
function
and
the
other
function
also
gets
these
two
points
and
the
way
that
it
received
them
is
basically
by
moving
them
into
this
into
this
function.
A
Now
it
gets
allocated
in
a
fixed
loan
location
and
when
I
call
the
length
function,
the
length
function
is
getting
called,
and
actually
you
might
notice
something
interesting
here,
which
is
this
ampersand
before
itself,
and
what
the
ampersand
means
is
just
what
it
means,
something
very
simple
which
is
you
can
you
can
use
itself,
but
you
can't
hang
on
to
it.
You're
not
allowed
to
go,
make
a
thread,
move
it
somewhere
else,
you're
not
allowed
to
do
something
that
would
cause
this
reference
of
this
line
to
outlive
this
function
call.
A
A
Sorry,
then
you
do
all
the
same
amount
of
work,
but
when
you
return
from
the
length
function,
you're
actually
confident
that
that
line
hasn't
disappeared,
which
means
that
the
compiler
can
look
at
this
whole
program
and
it
can
say:
okay
I
know
well,
it
doesn't
have
to
just
say:
I
know
that
I,
don't
I,
don't
have
to
allocate
anything.
We
as
a
programmer
have
told
Ross
exactly
where
it
should
allocate
everything,
and
so
that's
that's
fine.
That
I
think
you
can
sort
of
understand
how
that
could
work.
But
what
but
you're
probably
thinking
okay.
A
Well,
you
can
do
that,
but
what,
if
you
actually
make
mistakes
like
what,
if
you
need
to
hold
something
for
the
long
longer
than
the
size
of
the
stack?
And
let
me
look
at
a
really
simple
function
here,
which
is
the
function
which
opens
a
new
file
from
a
particular
path
and
prints
it
and
I'll
just
sort
of
walk
through
how
this
works.
This
is
a
more
complicated
example,
and
so
what
happens?
Is
we
make
a
new
file
and
what
we
do
in
the
same
function?
A
Is
we
read
from
the
file
and
again
remember
what
I
said
before,
which
is
that
in
rust?
If
you
don't
say
something
specific,
and
this
thing
that
you
say
specific
is
box
which
basically
means
put
this
box
this
up
and
put
it
somewhere
else.
If
you
don't
say
that
it's
always
allocating
things
on
the
stack.
So
basically,
what
we
said
is
open.
This
new
file
allocate
it
here
and
then
we
go
print.
A
You
know
print
line
that
says,
go
read
some
stuff
from
a
file
and
don't
worry
about
errors,
that's
what
unwrap
means
and
then,
when
we
get
to
the
end
of
this
function,
it's
basically
going
to
go
close
the
file
automatically,
because
it
knows
that
only
one
thing
has
access
to
at
a
time.
So
that
works
fine
and
as
expected,
and
you
can't.
Obviously
you
can
see
that
there's
nothing
dangerous.
That
could
happen
there.
We
can't
accidentally
refer
to
memory
that
we
didn't
expect
because
it's
all
self-contained.
A
Now,
let's
look
at
a
second
example
where
we
actually
read
the
file
to
a
string
inside
of
a
thread.
So
we
go,
we
say:
I
have
a
file.
Let
me
open
the
file
and
then
we
go
and
we
spawn
a
new
thread
and
we
read
from
it.
So
actually,
this
is
also
fine,
because
what
happened
here
is
that
we
read
from
the
file
in
the
first
place
and
then
we,
the
only
other
time
we
ever
you
that
again
in
the
entire
program,
was
inside
the
thread.
A
A
A
Obviously,
in
a
garbage
collected
language,
this
is
totally
fine,
because
what
will
happen
is
the
garbage
collector
will
hold
a
reference,
will
hold
two
references
and
we'll
wait
till
both
of
them
get
cleaned
up
and
then
it
will
clean
it
up.
But,
like
we
said
before,
what
we
would
like
to
be
able
to
do
is
not
have
to
worry
about
the
garbage
collector
and
what
hopefully,
you've
seen
so
far
is
that
in
many
many
cases
you
can
just
write
normal
programs
and
everything
will
work.
A
Fine,
and
you
won't
have
to
worry
too
much
about
these
rules
right,
but
you
may
write
a
program
where
you
decide
to
have
a
file
and
or
any
any
object
and
have
it
be
referenced
from
two
threads
at
a
time
or
there's
other
ways
to
have
this
happen.
And
if
you
go
ahead
and
do
that,
if
you
try
to
do
something
that
violates
the
ownership
rules
and
rust,
you
get
a
compile
time
error
and
what
that
compile
time
error
will
say
is
hey.
A
You
use
this
moved
value
file
and
there's
more
that
it
prints
out,
which
tells
you
exactly
where
it
was
used.
In
other
places
right
so
basically
what
this
means
is
that
if
you
actually
end
up
doing
something
where
you
try
to
do
something
that
would
require
a
garbage
collector,
then
obviously,
since
Russ
doesn't
have
one
by
default,
you
it
will.
A
Basically
it
will
give
you
an
error,
and
what
this
means
is
that
you
can
write
most
of
time,
normal
programs
that
you
they're
a
very
memory
efficient
that
are
very
fast,
that
are
that
don't
that
are
also
very
safe.
But
you
do
have
to
worry
about
the
case
where
you're
doing
something
dangerous,
but,
unlike
in
C
or
C++,
you
get
notified
when
you
try
to
do
something
dangerous.
A
It's
safe,
it's
like
kind
of
a
magic
combination
and
is
how
it
works
that
there's
sort
of
a
set
of
rules
that
you
have
to
follow
about
who
gets
to
own
what
pointers,
but
it
ends
up
being
very
powerful,
so
that's
called
ownership
and
if
you
start
learning
rust,
make
sure
you
pay
special
attention
when
you
come
across
the
section
of
the
guide
or
whatever
tutorial
that
talks
about
ownership.
So
let
me
go
sort
of
back
to
the
beginning,
which
is
why
does
this
end
up
mattering
for
anybody?
The
reason
it
end
this
ends
up.
A
Even
the
people
who
write
browsers,
who
are
the
best
people,
as
plus
hackers
in
the
world,
make
mistakes
and
get
exploited,
so
I
was
never
very
comfortable
experimenting
in
my
own
applications
with
C
code
or
C++
code
because
they
were
so
dangerous
and
what
this
lets
you
do.
What
rust
lets
you
do
is
lets
you
say:
I
have
some
area
that
has
been
driving
me
crazy
performance,
wise
I've
tried
everything.
It's
been
crazy.
I've
spent
all
this
time.
You
know,
reading
the
C
code,
learning
how
the
JIT
works.
A
Be
able
to,
you,
know,
beat
them
out,
and
so
obviously
don't
do
this
whenever
performance
doesn't
matter,
but
when
performance
matters,
probably
your
competitors
have
similar
performance
requirements
and
you
could
you
could
compete,
you
can
out-compete
them
and
just
in
general,
it's
safe,
I.
Think
it's
easy
to
think
about
low-level
code
and
say
low-level
code
is
either
you
know.
Low-Level
code
is
super
dangerous
and
it's
so
hard
to
write
and
there's
all
these
crazy,
s'I,
macros
and
what's
happening
here
and
rust
is
a
safe
language.
A
It's
a
productive
language,
it's
not
as
high-level
and
as
productive,
maybe
as
Ruby,
but
if
you
care
about
performance
I,
think
it's
great.
It's
safe,
Rus
enables
a
whole
new
generation
of
high-level
programmers
to
write
systems-level
code.
So
I
think
what
you
should
ask
yourself
is:
what
can
you
do
with
that
power?
Thank
you
very
much.