
Rust by Example - giis
http://rustbyexample.com/index.html
======
giis
Can anyone share some insights on how time much did it took to get comfortable
with Rust? I'm getting started and crawling with concepts like ownership,
mutability

~~~
jackyinger
If you want to do the basic things that rust wants you to do it doesn't take
that long.

However if you want to create any graph like data structures you need to go
into unsafe rust.

For example, the std doubly linked list uses unsafe with error handling to do
inserts because the compiler cannot be sure that an insert is safe.

In my opinion Rust's safety is overhyped and entirely dependent on good
implementation of unsafe code. And judging from the liked list example there
is no way for all rust code to be intrinsically safe.

~~~
caconym_
Show me a programming language that lets you manipulate raw pointers while
providing the same safety guarantees as safe Rust code (i.e. have your cake
and eat it too) and I'll accept this as a valid criticism of Rust. Until then,
I"m going to keep thinking that Rust provides a reasonable, practical
compromise.

For about a year, I've been regularly using Rust to write real software that I
actually use, and I've never had to write unsafe code. I'm trusting other
people to do it, which is never not the case, no matter what programming
language I'm using.

~~~
jackyinger
By definition manipulation of raw pointers is unsafe. So no language can do
that. Sure Rust's typed pointers can be safe as long as libraries fulfill
their garuntees.

My main point is that safety rests upon the library correctness. And I can see
the value of the interlocks this provides. However it is not infallible as the
word safe suggests.

I'll admit that I have not grokked rust, but I did give it a reasonable try.
Perhaps all my C hacking has ruined me. :)

~~~
caconym_
> My main point is that safety rests upon the library correctness. And I can
> see the value of the interlocks this provides. However it is not infallible
> as the word safe suggests.

I don't disagree with that. Sometimes I don't totally love how the Rust people
market the language, and I can see how the statements they make about safety
could rub their target audience the wrong way, but I don't know how I'd do it
better. I really do think the language does a great job helping programmers
write fast, safe, bug-free code... once they get over the learning curve.

If you ever feel like taking another crack at it, this is the reference that
made the memory model stuff (which is the trickiest bit IMO) click for me:

[http://cglab.ca/~abeinges/blah/too-many-
lists/book/](http://cglab.ca/~abeinges/blah/too-many-lists/book/)

------
kkirsche
As a heavy ruby, go and Python user what kind of scripts or programs should I
consider migrating to rust to help with learning it? Or is it really just low
level stuff that I can't justify the additional complexity

~~~
moron4hire
When you say "low level stuff", what do you picture?

~~~
kkirsche
I picture things like drivers, kernel extensions, etc. I do a lot of network
programming with raw sockets and custom packets, parsing Netflow / IPFIX, etc.

~~~
Manishearth
Nah, it doesn't have to be that low level.

Servo, for example, doesn't deal with this; it's a web browser.

Think of the use cases where you'd use C or C++, and Rust should work there.

You probably can rewrite Ruby scripts in Rust if you want, but the
productivity benefit depends on the kind of script. But for the purposes of
learning the language it doesn't really matter.

------
fjrieiekd
Anyone here using Rust on mobile? That's the potential usecase that interests
me the most, but given that the tooling still has a lot to be desired, and a
lot of mobile code is vendor-specific anyways, I'm not sure it makes that much
more sense than just duplicating those shared parts between Swift and Java.

I could see it for small modular parts that are better suited for native code
and when one doesn't want to use C, perhaps, or, of course, for
infrastructure-level projects like Servo.

I just wonder if I'm barking up the wrong tree because much of the Rust
interest I see seems more heavily weighted in infrastructure and backend, not
in user-facing code.

------
Wonnk13
great website. I think i'm going to start with C++ just so i get a foundation
of what a systems language is and appreciate the innovation that Rust brings
to the table.

I'd be really curious to know if website format exists for other languages.

~~~
anuragsoni
There is a website with a similar format for the Go language:
[https://gobyexample.com](https://gobyexample.com)

------
ne9xt
as a noob interested in rust, what is its primary application? why do people
use rust vs another language?

~~~
IshKebab
I think the best way to put it is that Rust has no overhead. You'll never be
in a situations with Rust where you say "Oh damn I wish I had written this in
X because Rust has this annoying limitation". Some examples of limitations in
other languages:

* Python has a GIL (Global Interpreter Lock) so writing multi-threaded Python code is more or less impossible (there are some workarounds but it still sucks).

* Most garbage collected languages (e.g. Java, C#) suffer from 'stop the world' pauses which make doing low-latency realtime stuff a pain in the arse. For example on Android they recommend you don't create any objects in your draw functions to avoid invoking the GC. It's kind of like "Java is great, no need to worry about memory, but oh... you really have to be careful about memory here." Not all GC languages are like this, e.g. Go now has sub-millisecond pauses.

And aside from that it is safer than C/C++. So basically it will be used
wherever C++ was before.

The big downside is that it is definitely one of the hardest languages to
understand and write. That can make you less productive. If I were on a varied
team that included less skilled people I would definitely choose Go over Rust
if it were suitable - it is a _lot_ simpler.

~~~
nine_k
If one just wants simplicity, why not pick C, or even Basic-80? They are
simpler than Go.

For the increase in complexity, Go gives you concurrency, and Rust, safety, on
top of other things.

~~~
ekidd
> If one just wants simplicity, why not pick C, or even Basic-80? They are
> simpler than Go.

It's very simple to write _bad_ C. Writing safe, correct C with no security
vulnerabilities is surprisingly hard, which is a major reason why most OSes
need to apply regular security patches.

Rust gives you speed, concurrency and memory safety at the same time. This is
not free: You need to know about values, references, stacks and heaps. And you
need to write your code so that objects have a single, clear owner. It also
helps to be somewhat familiar with generic types and functions like `map`—some
old-school C programmers might have issues with parts of Rust, but C++
programmers (or C programmers who know JavaScript) should be fine.

If you're willing to pay that price, and spend a week or two making friends
with the borrow checker, Rust is a fantastic and versatile tool. But for many
programmers and applications, that price may be too high.

Rust will hopefully remain simpler than C++. But it's always going to be more
complex than Go or Ruby. I have no idea whether Rust will wind up simpler or
more complex than modern JavaScript, though. :-)

~~~
nine_k
My point exactly. Being simple is nice, but not enough.

This is why I (ironically) offered to use Basic-80, which is even simpler than
Go, replying to a text that suggests to choose Go over Rust for Go's
simplicity.

------
epynonymous
when i taught myself golang, gobyexample.com was the best resource for
learning golang! so i'm hoping this is on par with that. what gobyexample
lacks is more complicated examples, but it gets you started with just enough.

rust seems like a great language, but i'd like to hear about some advantages
versus golang.

~~~
giis
If I'm not wrong, I think golang and rust target different group of
developers. Rust portrayed as low-level system level lang. potential
replacement for c/c++. Where golang is touted as potential replacement for
high-level application which are currently being written in Python/Ruby/PHP

~~~
nicoburns
This is partly true, but there's a lot of crossover. I've been happily using
Rust as a node.js replacement for the last few weeks.

