
First Impressions of the Rust Programming Language - dailymorn
http://jakob.space/blog/post/First+Impressions+of+the+Rust+Programming+Language
======
Animats
Not too helpful. Just comments from a new programmer.

I'd like to hear something like "This is how our team used Rust to do (really
hard thing involving heavy concurrency and lots of state)". From someone _not_
involved with the development of Rust.

I was recently looking at a large, non web related C++ program which needs to
be made multi-thread to increase capacity. I realized that if it was in Rust,
it would be much easier to break out functionality into another thread. You
need to classify data as immutable, locked, or unshared to make the program
multi-thread. Rust has language support for that. C++ does not.

~~~
nevi-me
It might not qualify as "really hard thing involving heavy concurrency and
lots of state", but I'm nearly done writing a service that interacts with
[http://tile38.com](http://tile38.com). I initially wrote it in Kotlin, and 2
weeks ago I ported it to Rust.

I'm still learning the language, so I haven't touched the "fearless
concurrency" stuff, but so far it's looking __very __good.

~30% CPU time, 1-5% RAM use at peak; compared to the JVM.

I plan on writing about it, and open-sourcing the code (both Kotlin and Rust
repos). Chasing a hectic work deadline at the moment.

------
steveklabnik
As I wrote to the author on Lobsters:

Glad you liked TRPL! I agree that some of the examples can be too abstract at
times, it’s tough. Totally open issues if you want to talk about it; I’m open
to improving things, but I’m also pretty particular about the book.

~~~
weavie
I'm really looking forward to getting the hard copy!

~~~
steveklabnik
Me too! It’s being printed right now... so close!

------
abalone
_> Compile-time memory management requires designing your programs in a way
you might not be used to, but it definitely beats manual memory management, or
letting a runtime take care of garbage collection._

What about Automatic Reference Counting a la Swift / Objective-C?

Seems like a nice blend: compiler assisted, much less runtime overhead than
traditional garbage collection, simple programming model.

~~~
cortesoft
Rust supports reference counting for places where you need it. There is both
the RC and ARC datatypes.

~~~
steveklabnik
And to be clear, Swift’s ARC and Rust’s Arc are different; automatic vs
atomic. Swift’s ARC is automatic usage of Rust’s Arc type, if that makes any
sense.

------
rdc12
"Also, I've been fairly critical of Rust in the past because that view was in-
line with the opinions of my friends, but now that I've decided to go out of
my way to learn a new programming language, I might as well use this as an
opportunity to see if my criticisms were unfounded."

While this is an honest comment, why and how can you be critical of a language
you don't know. Skeptical sure, but critical?

------
alexeiz
Is it me, or does the Rust compiler produce terribly unoptimized code? Just
compare it to the equivalent C++ code:
[https://godbolt.org/g/Jdfkm6](https://godbolt.org/g/Jdfkm6). Both Clang and
GCC produce really lean binary output.

~~~
steveklabnik
Sometimes. It just depends. Some possibilities:

1\. The parent didn’t say if they compiled with optimizations. I bet they did,
as the code would probably look even worse without, but who knows.

2\. This isn’t apples to oranges, as you’re not doing formatting here, right?

3\. The formatting code makes various trade offs; it’s not optimized for
speed, more for size, in my understanding.

4\. Codegen bugs do happen. Maybe this is a degenerate case.

In general, if the code is significantly worse, then it’s a bug.

------
agumonkey
first thing that jumps (sic) is that comparing puts to formatted print is not
worth of a gentleman.

~~~
yawaramin
How would you write it, out of curiosity?

~~~
Tobu
There's an example of using stdout.write at the top of this page:
[https://doc.rust-lang.org/std/io/fn.stdout.html](https://doc.rust-
lang.org/std/io/fn.stdout.html)

    
    
        use std::io::{self, Write};
    
        fn main() -> io::Result<()> {
            io::stdout().write(b"hello world")?;
    
            Ok(())
        }

~~~
steveklabnik
I should improve this example, in its current form you could drop the ? and
the Ok stuff...

------
earenndil
> if let is a syntax construct that I don't think any other language has

AFAIK (not too familiar with rust or c++), you can do something like this:

    
    
        if (Maybe may = whatever; may.issome)

~~~
chrismorgan
`if let Some(x) = y { … }` is equivalent in Rust to `match y { Some(x) => { …
}, None => () }`: pattern bindings are available. Thus it is quite different
from `if y.is_some() { … }`.

~~~
earenndil
Is it? It does something with y if it is something, otherwise it does
nothing...

~~~
chrismorgan
To make clearer what I meant by pattern _bindings_ being available:

    
    
      if let Some(x) = y {
          println!("y has a value, {}", x);
      }
    

Whereas with a method, the contents of the variant are not bound:

    
    
      if y.is_some() {
          println!("y has a value, {}", /* uh… */);
      }
    

In Rust, pattern matching is the only to get at the contents of an enum.
Methods like is_some() are just this:

    
    
      pub fn is_some(&self) -> bool {
          match *self {
              Some(_) => true,
              None => false,
          }
      }

------
nbw310
man 3 strdup. Why is this upvoted? If you are a new programmer, don't read
this nonsense.

~~~
mwcampbell
It's true that on platforms where strdup is supported, the C example could be
written more succinctly with strdup. But strdup isn't part of the ANSI/ISO
standard, at least according to the man page on Ubuntu 16.04. And even when
using strdup, you can't get away from manual memory management; you still have
to call free (or strfree) afterward.

Furthermore, the field of programming is so vast that it's unreasonable to
expect someone to know every nuance of a given language, especially if it's
one that they don't use heavily.

So I don't think there's any good reason to dismiss the whole article as
nonsense.

