419 points · by steveklabnik · 9y ago · 266 comments
What it comes down to again and again with projects I think about using Rust for is "how much extra effort is it going to be compared to a language with good libraries for this?" Often I don't use Rust just because the cost/benefit of having to (re)write code that would otherwise be in a library doesn't make sense.
I'm still bullish on Rust. I know it takes time and it's an unfair competition against the likes of Node and Python (with a zillion library authors), or Go (with a huge company dedicated to a kickass standard library). But nonetheless that's the playing field, and I think a stronger library ecosystem is probably the most important thing for Rust adoption right now.
Well, that and not having to use nightly rust for serde, but you already fixed that.
On the other hand, if you're looking to fill out your resume or get some open source credentials, you can see this as another frontier opening up (depending on how popular you think Rust will be in a few years). Become the solution for that need in the Rust ecosystem, and there are probably massive reputational benefits to be reaped. In some ways, reputation is better than money, because when invested wisely can have a much higher rate of return, and depending on location and circumstance, can be levered into high-paid employment.
One person's problem is another person's opportunity.
You should consider publishing an official, printed book. I would totally pay $30-40 for something like this. And once it's already written, the actual publishing shouldn't be too time consuming (but idk lol). I think that there's a lot of people who'd buy it just to support the project.
On one hand, I do have environmental concerns, but on the other hand, I feel like my retention rate with print is like 70% as opposed to like 40% with digital.
One of the sections that was most useful to me was comparing how memory is laid out in a few different languages with a few different concrete code examples. These comparisons really helped me "get" borrowing.
For one, I would be surprised if a non-"expert" (which is, I presume, why you're so dismissive of Rust developers) could write a book that gives an accurate/useful mental model of Rust: teaching is the true test of one's knowledge about anything. Additionally, people paid to work on Rust and on Rust documentation/teaching materials (i.e. "Rust developers") are the people most regularly interacting with all sorts of beginners, and thus are likely to have great insight into, for instance, the common difficulties people hit, rather than just anecdoata about their own personal experience/background (which is good too, but is only one point of reference for things that people find hard).
Rust developers can write beginners books (indeed, the Rust book is designed to be this, and the second edition succeeds better the first, I've heard) just as much as non-Rust-developers can write expert books.
A C programmer, a Python programmer and a Java programmer should write the book together, with expert insight from a Rust pro.
As an example, I found the explanation of trait objects incredibly confusing when I read the book. They confused the subject by immediately talking about static vs dynamic dispatch of functions, which is really an implementation detail and performance consequence of using them and not a part of what they are logically. An outsider might have started with a simple explanation of what a trait object is (an instance of a trait where the compiler cannot determine the concrete type at compile time) and make that clear before diving into the consequences of choosing to use one in your code.
https://www.packtpub.com/application-development/rust-essent...
https://www.amazon.com/Programming-Rust-Fast-Systems-Develop...
I have purchased it and it's pretty good. Although it really seems to be geared more towards experienced systems programmers. The online book is much better for beginners, IMO.
The main problem I have with Rust is that it's not up to the task of dealing with C APIs, particularly POSIX. The issue I got stuck on was https://www.reddit.com/r/rust/comments/47a0s3/dealing_with_v... . There are two possible things Rust could do that would make me give it a second chance: either commit to maintaining bindings for all of POSIX and libc as part of Rust core, or fold rust-bindgen into core and get it into shape.
Creating higher-level libraries like Tokio is nice for some use cases, but right now Rust doesn't have a working safety valve for things C can do that Rust can't. This greatly magnifies problems like lack of bindings for select() (see http://esr.ibiblio.org/?p=7294&cpage=1 ; I too ran into that problem, and lost a few days to it.)
rust-bindgen has been improving a ton, and it is in fact on that roadmap, under
> Integration with other languages, running the gamut from C to JavaScript.
I didn't try the nix crate at the time, but looking at it just now - it doesn't solve the portability issue. It defines struct Termios in https://github.com/nix-rust/nix/blob/master/src/sys/termios.... , with something #ifdef-ish branching on operating system, but not on CPU architecture. On quick inspection, I think it's probably incorrect on x86-32, and this crate is definitely a major liability for portability.
(Also, I'll stop here and only reply on our Reddit conversation, ha!)
Anyway, huge fan of what the Rust devs are doing. It's truly awesome.
I like Rust, but IMO no language will ever again be Java-level popular (not even Java!) in the same way that e.g. there will never again be a band as big as the Beatles. Technological contexts have changed such that niche languages can now successfully thrive and counteract the lower switching cost that comes with a monoculture; while certain languages "in the middle" will still dominate, the long tail will get longer and subsequently lower any dominant language's market cap.
What do you mean by saying mutability is for safety? That's a very unusual opinion.
Copying everything every time isn't a solution in a multithreaded world if you actually want your threads to share data.
Since the borrow checker happens at compile time, the whole mechanism is "zero cost". This results in more efficient code, because you can do things like safely hand out references (pointers) to privately held pieces of data without needing a heap allocation to track the pointer (e.g. shared_ptr in C++); the final code needs no lifetime checks, because the compiler did all the analysis for you.
I imagine the combination of ownership and immutability also lets the compiler reorder, eliminate and simplify generated code better than most other languages (Haskell being a possible exception here). Not sure if Haskell-style automatic parallelization is planned.
What I actually would like is a few "Books" like "Rust for C++ people", "Rust for Go people", etc. Those would describe in many examples how things that are achieved in language X using A, B, and C can be done with D in Rust.
Personally, I would like a "Rust for Gophers" book that would describe things like how does Rust do composing (that is, how to do what Go calls embedding), interfaces in Rust (with dynamic vs static dispatch), HTTP in Rust (this may be waiting for Tokio?), how to model your application's types and not get into who-owns-what traps.
Also, what I really want is some kind of a list of Rust "warts" and their explanation. Like the fact that sometimes you can't do a.b().c(), but have to write tmp = a.b(); tmp.c().
I fully agree that more of this kind of thing would be great.
Also, as someone who've tried to get into Rust three times now, I've been thinking, have you or anyone from the rust documentation team ever had sessions where you just
- take a random C++/Go/Python developer
- ask them to solve a not-too-simple but not-too-hard task, something that'll generally take them less than an hour in their "native" language, in Rust
- look and take notes on their struggle with it
This might shed some light on why people (like me) have so much trouble getting into Rust.
I'm not sure enough time has passed to tell what Rust's warts truly are. I always joke String should have been called StrBuf...
I do this, yes. This is one of the reasons I hang out in IRC so often; it's an effective way to collect these kinds of things.
More data is always better, and collecting it across multiple venues. I don't think IRC is inherently going to be a representative sample. It's one of the reasons you'll see me pushing for details in Rust threads here, for example.
a.b().c()
b here is temporary, and so is freed at the end of the line, making the return of c dangling let temp = a.b();
temp.c();
Now that the return of b() is not temporary, it will last to the end of the scope and so c is fine.I love it. Short and simple, describes what Rust is. Between that and "an anti-sloppy programming language", pretty sure the marketing is there. Well done community leads, this is exciting.
If you need to write a library to implement the latest protocol, or render the latest image format, or parse the latest serialization format, then Haskell seems great. Unfortunately, the resulting library will be useless except to other Haskell programmers. Nobody wants to link in libXYZ.a and get the entire Haskell runtime, starting threads and doing GC and sending and catching signals.
I tried implementing a handler in postgresql so that you could write user-defined functions in Haskell. I made little progress, even with help on IRC and elsewhere. Any non-trivial function would need to define its own types and use some libraries, but it was far from clear how to do that and the best advice I got was to dig into ghci and try to use some ideas from that. I started down that path, ran into runtime issues, and that was the last straw and I ran out of steam. And that was only to get the most basic functionality: call into haskell to do some computation and return.
I highly encourage people to drop any MS misgivings and give it a try (honestly that was the biggest thing for me to get over).
Also, a nice history for UI native widgets will be a plus. This is ask a lot, I know.
Right now I have some projects where the less-worse option is .NET, swift if only iOS+Linux, Delphi is because cost (and free pascal is unfocused). Then obviously C++, but that is where I draw a line (ie: For a C-like language Rust is the only that look nice to me. I wish pascal instead or similar)
Because it compiles directly to C, I've found it reasonably easy to bring into different environments myself, though I've not attempted iOS yet :)
Edited to add: Also check out https://github.com/yglukhov/nimx
I saw the long awaited Non-Lexical Lifetimes tentatively mentioned in there, and I can only hope this will help move things forward, since it's pretty frustrating spending time fighting the borrow checker and refactoring correct code that really ought to run as-is.
Cheers and happy 2017 to the Rust project!
I'm extremely new to rust so I don't know if fighting the borrow checker is in my near future or something I will largely avoid.
I'm still learning Rust, but I thought the fact that you could have as many immutable borrows as possible would limit what errors the borrow checker could throw at you.
- GTK is a painfull to install.
- Conrod: I was unable to do an hello world application with it. It just miss some tutorial.
- KISS-UI: some dll to install
- Qt: not totally free
- Neon to plug on Electron: I'm not sure if I can do some callback from Rust to the GUI with this method.
I finnally give up to play with Electron in javascript.
Qt has been free for decades and is LGPL these days, about as free as it gets. Is there some Rust-specific issue, or is this just decades-old FUD from the GNOME project?
Also pretty bad on Windows AFAIK?
My personal wish would be for an easy way to use Servo to render the UI.
Also no longer cross platform. LibUI (https://github.com/andlabs/libui) looks promising but I don't think the rust bindings are being worked on.
At the end of the day, the primary thing I want from my PL is to boost my productivity. In the kinds of software that I write, I can tolerate bugs and GC. Does Rust actually make me more productive?
If you want to remain relatively productive while building things that are one or more of (large, fast, safe), it's an excellent choice.
I can type reasonably correct code much faster than I can reason about how the program should work.
Compared to C++, Java, or even Go, it's anywhere from competitive to significantly better.
You might want to rewrite that statement. Or at least clarify, what kind of software that you write that can "tolerate bugs" and what kind of bugs you're talking about.
1. I write many kinds of software, but specifically at that moment I was talking about web applications.
2. "Tolerating bugs" is true of literally every software, except maybe things that are proven to be correct in the mathematical sense. Web applications often have parts that may cause inconvenience if there is a bug, but data is not lost, productivity is not lost, and certainly no lives are lost.
However, what I still miss is bootstrapping from source. It would make porting to other platforms much easier. It confuses me that Rust is proclaimed as a safe language while anyone is forced to install a binary with wget | sh.
Can I create a Windows executable for Windows on Linux?
> Can I create a Windows executable for Windows on Linux?
Yes, but it's a little gross at the moment: https://github.com/rust-lang-nursery/rust-forge/blob/master/...
We do plan for all of this to be much, much easier in the future. Working on it.
> I've heard that it is ready and that it's not quite ready.
The foundations are strong, but the details are tough. So like, doing the cross-compilation is there, and is the simple bit, it's all of the stuff around it: linkers, other platform stuff, things like that. But the foundation to make all of this easy is in place. It just needs time and effort.
Rust has been putting much effort into "l33t features" in template land. I fear Rust may be going down the C++/Boost template metaprogramming rathole.
From that C++ thread on HN right now:
https://news.ycombinator.com/item?id=13584167 https://news.ycombinator.com/item?id=13583935
Call me skeptical, but I do not believe ADDING stuff to C++ is going to make it more competitive against Python in ease of use. Especially as programmers will still always be free to use all features, and any large enough project is going to end up with all of them.
That being said, lifetimes and traits being both complex and unfamiliar features, there's always going to be quite of a learning curve. But one can always reduce the amount of papercuts. If nothing else, one can at least make the documentation better, the ecosystem libraries better and error messages even smarter.
It's old enough that it's before Rust 1.0, so some of the syntax is a _teeny_ bit wrong (int isn't a type any more, you'd use isize) but the macro picture is the same.
The Rust stdlib is mostly core abstractions and platform-dependent stuff.
Given that, why should they be in the stdlib? The rand crate is officially blessed and the one everyone uses.
Rand is a vocabulary crate (traits Rng and Rand are used for inter-crate exchange), so it's very sensitive to version coupling.
"vocabulary traits" like this are a good candidate for the stdlib for exactly this reason, maybe a good compromise would be putting _those_ in the stdlib, but leaving the implementation outside.