134 points · by nercury · 11y ago · 183 comments
http://www.oreilly.com/programming/free/why-rust.csp
"One of the original designers of the Subversion version control system, [Jim Blandy is] a committer to the SpiderMonkey JavaScript engine, and has been a maintainer of GNU Emacs, GNU Guile, and GDB."
> But all those other languages include explicit support for null pointers for a good reason: they’re extremely useful. [....] The problem with null pointers is that it’s easy to forget to check for them.
There is no inherent reason for that; just that mainstream languages which support `null` haven't been checking `null` usage. Some of the recent ones do. For example, Kotlin has non-nullable types by default, and null types have to be explicitly marked and checked for null-ness.
Even for Java, null analysis is built into Eclipse with the help of annotations. Though, ofcourse, it would be far nicer to have it baked into the language.
What's important is that you can't use a value of type Option<T> as if it were T; you have to check it first. This is helpful for non-pointer types as well; I include an example of that.
Without collapsing that indirection, Option<Option<T>> is perfectly expressible:
Just (Just foo): <ptr> -> <ptr> -> foo
Just Nothing: <ptr> -> <0>
Nothing: <0>
It's true that some languages expose "nullable references" as a distinct type and not a detail of representation, and it's true (... and sometimes obnoxious) that this doesn't layer as nicely (in particular, it's not a functor).I don't think so. It's just a pointer to a pointer, rather than a single pointer. That is,
int **value;
and either value == null
or *value == null
or **value == some value of interestWe now need a "programming in Rust" book which is not by one of the Rust developers, who are too close to the design.
I've assisted Jim in giving presentations on Rust at OSCON this year, and trust me when I say that he has no qualms about criticizing the language when he sees fit. His perspective is definitely that of an outsider's, and like you I agree that that's ideal from a pedagogical point of view.
That's not entirely true. There are some mechanisms that you can't really do in C++, at least not without a lot of boilerplate. And Rust's generics aren't quite as powerful (as in metaprogramming) as C++'s yet. I hear they're working on it, though.
It's easy to define a list of integers in pretty much any language,
class IntList { void addInt(){...} }
Most languages let you make a generic List, class List<T> { void add(T){...} }
The thing that's cool about HKT, is it lets you swap the other side, class T<Integer> { T operate(Integer) }
So you can deal with a Set or a List or an Optional or whatever might want to deliver integers. It seems a little goofy, but it's sort of like a Super Lambda. an anonymous function can only really do its one thing, but this lets you bundle a bunch of related lambdas together, so if you have, say Pay, you can group together all the different types of tax that are applied to pay, calculate total tax, etc. And it works over whatever random data structure you wantIt seems a little crazy at first, but with clean syntax, it's a fantastic way to split the work apart from the way the data is represented.
* what kind of animal should it have on the front?
* will it tell me 8 different, confusing, obsfucated ways to do something that would be much faster with printf?
* will it do that in chapter 1?
* ???
* profit?
The std::thread::scoped function used here is undergoing some redesign...
/grumble /grumbleYes, I know, it'll all eventually settle down, but darn its annoying at the moment trying to use stable.
(The 'crossbeam' and 'scoped_threadpool' crates have different implementations of this idea, though.)
While this is probably factually true -- I've had quite the opposite experience. :(
- I want to write benchmarks for my code, but I need `#[feature(test)]` AKA nightly.
- I want to [format my Rust code](https://github.com/nrc/rustfmt), but I need nightly.
- I want to use Huon Wilson's SIMD crate, which requires nightly.
I'm not saying these things should be stable right now, but I am saying if you try to use Rust right now you _will_ encounter a lot of stuff marked as unstable and/or only usable on nightly due to XYZ. I still think Rust is amazing and everyone should give it a shot though, but it's not as stable/polished experience as I think it will be in say a year from now. The language is stable, but the ecosystem just isn't yet.
P.S. You've helped me personally all too much over the Rust IRC channel, so thank you a million times for that! :)
I also think that year-from-now Rust will be way nicer than at the moment, it's absolutely early days. But there's a lot you can do, even on stable, right now. This is why I said it depends on what you're doing. Some use cases have absolutely no choice but to use unstable things. Others have options, and others only use stable.
As to your three points:
1. You can configure things so that you only need nightly when doing benchmarking, and run on stable the rest of the time.
2. Compiling `rustfmt` needs nightly, but using it doesn't, as it's a binary.
3. Yeah, the SIMD stuff just happened, so it's gonna take some time.
Also, rustfmt is a binary which can work without nightly once you've compiled it.
For example, try using https://github.com/serde-rs/serde without nightly.
Possible? Totally.
A right pain compared to using nightly? That too.
I'm also a huge fan of the Chapel Programming language. Anyone else think they're both hitting a sweet spot and would potentially have a beautiful love child?
It may come as a surprise to some but most systems engineering has very little hard computer science involved and is mostly about achieving very simple tasks in reliable ways with very robust error handling.
You rarely implement novel data-structures or algorithms. Not shipping with cyclic data-structures in Rust is not really a problem for most systems applications. That said, you actually -can- build them in Rust, and it's likely there will be nice libraries with various different allocation/memory management and other runtime tunables and performance tradeoffs.
If you exclusively consider hard computer science problems as "hard problems" then no, Rust is probably not for you. Consider Haskell or Julia.
And frankly: Your definition of "hard" is a bit restrictive.
not a fan of C++ but I personally think having to wade through the building blocks of C was an immensely valuable reverse turing test (ability of human to exhibit human-like behavior? apparently this term is already taken but you get my idea) and I bemoan the future where everyone is protected from their mistakes. How else did one build motivation to do it right? The gamble of a mistake is much more fun than of a compiler error.
??? These would be super easy to build on top of Send/Sync and lifetime tracking.
You might be confusing Rust the language with a hypothetical Rust/OTP or Rust/HOL or something.
Without those, we're going to see a hundred different solutions crop up, none of them being interoperable.
I'm also sort of hopeful that higher-kinded types can do something about writing code that can run on any such system. If you can have some functions on an abstract Promise<T> type, like fn then(Promise<T>, fn(T) -> Promise<U>) -> Promise<U>, it doesn't super matter which backend you're using. (As I understand it, JS is already here, because they can duck-type their promise spec.)
https://crates.io/search?q=graph
> No support for trying
do I need to have functional experience for exposure to that? Only thing you listed that I haven't heard of.
I would not be shocked if someone figured out a brilliant way to add dependent types to Rust 1.x within the next few years.
QED? Really? I'm not so sure I trust the author to give rust fair treatment anymore. An operating system that does multithreading is not the same as a modern machine.
Edit: Any brave down voters want to explain why? Threads are a way to model concurrency. There are other ways.
If you don't want to come across that way, give us some explanation of what you're thinking and why. Give us some evidence that your statement is true. Something besides just dogmatic assertions that you're right and the author of the article is stupid and/or biased.
Moving on...
In the context of the OS, multithreading (or something essentially equivalent) is the only way to exploit the abilities of "modern" machines. But "modern" doesn't mean very modern (at least, as I understand it). It means the difference between MSDOS and Windows: "Windows is multitasking, whereas DOS... DOS is serially multitasking." (I don't recall who said that, but it was brilliant.) Without this capability, you're only running one program at a time.
Now, I don't care if you implement this as "theads" or something else, but if you don't have it, your OS is pretty much worthless, and has been since about 1990.
> In the context of the OS, multithreading (or something essentially equivalent) is the only way to exploit the abilities of "modern" machines.
I noticed that you qualified multithreading with "or something essentially equivalent". I guess you would agree that qualifying it this way is a good idea. Mr Blandy did not care to do that though: "[...] is the only way to exploit the abilities of modern machines."
I don't like that because it sounds like he's trying to popularize one approach to concurrency without even acknowledging that it is just one approach.
Note as well that Rust intends to have world-class support for a wide variety of approaches to concurrency and parallelism. Threading and channels are already in the stdlib, and fork/join and SIMD are in the works now. The goal is to enable the programmer to be able to choose the best tool for the job.
Edit: No that's not exactly true http://stackoverflow.com/questions/7005759/erlang-on-multico... But they do spawn a processes for each core.
Each thread runs a scheduler and the many Erlang processes are balanced between the schedulers. There is still only one OS process though.
http://erlang.2086793.n4.nabble.com/Some-facts-about-Erlang-...
If you're talking about systems programming threads are by and large the main mechanism for concurrency.
Only in really odd architectures do you see things like manually DMA'ing to separate execution units(ala PS3) and are certainly the exception to the rule.
I believe it was Windows that really popularised multithreading as a form of concurrent programming as process creation is so expensive on that platform. I recall Linus ranting against adding threading to the kernel on more than one occasion.
When I went from EXEC 8 to UNIX in 1978, my main observation was that the I/O was better but the CPU management in UNIX was much worse.
You can see Aaron's initial work on the basics (memory management) on his blog[1], and a higher-level introduction into the power of Rust's concurrency on the main Rust blog (also written by Aaron)[2].
[1]: http://aturon.github.io/blog/2015/08/27/epoch/
[2]: http://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.ht...
That said, I wish they would have looked a little further outside Reddit's homepage rendering for parallelization inspiration. Reddit does not take a long time to render. However, CNN.com [which they looked at too] does, so...