News for hackers. Stuff that matters.
Re:Writing a website in Rust by ilaksh on Saturday May 30, 2015 @01:03PM (#9630794)
Here's something that most of you will probably learn the hard way: popularity and merit are not the same thing.

Rust is very popular now. That doesn't mean it has a great design. One of the very first design decision/belief they made was "no code can perform with garbage collection". Well, garbage collection does cause quite a few performance problems, but that doesn't mean it can't work if you engineer it right.

Personally I think Go and Nim are better languages as a general statement, both for applications and systems programming.

I know I am going out on a limb making a negative statement like that, and previously Nim developers have tried to discourage me from saying negative things about Rust. Those guys are smart and have social skills and they realize they should be careful to be nice to Rust developers because sophisticated developers looking for things like performance, type safety, etc. with a C or C++ background are really going to benefit from Nim if they give it a chance and Rust developers are prime candidates for Nim conversion.

So let me just say clearly that I don't associate with the main Nim community, the core developers, or anyone really. Nothing I say here reflects on them I hope.

I literally have no friends in fact.

I don't understand people, or pay much attention to them, or interact with them very much. When I do interact I say what I really think, not what people want to hear.

What I DO understand is technology. From a very early age I have been programming in everything from different types of assembly language to C to C++ to Ruby, Javascript/CoffeeScript/ES7, different variants of SQL, Rust, Forth, OCaml, etc.

Mozilla is a leading technology organization with many contributors. Rust is a new technology with quite a few people innovating on it.

Unfortunately, Rust starts with a bad design decision and never really recovers from that design decision. The values and perspective are lacking a modern, contemporary perspective.

The Rust worldview is trapped in the C++ era.

I have been primarily a JavaScript developer both on the front and back end for many years now. Why? Because I like to make useful applications and I am sane and paying attention.

But in a world where people were better informed and had better judgement and the best things won out rather than the most popular, Rust would be an obscure language being toyed with by a few academics for (perhaps?) implementing certain parts of kernels, the new browser from Mozilla would be fully peer-to-peer capable (using IPFS/gittorrent/swarm/ndn etc), written in Nim of course, use JIT/VM/something Nim for scripting, and have thrown out JavaScript/ES6/ES7 AND CSS for good. Of course, in this ideal world there would be no google monopolizing all advertizing and capturing most good engineering talent, since semantic markup and p2p query would also be be built in to this browser, making google irrelevant. The default mode for the browser would be virtual reality, with the ability to render 2d operating systems or markdown/images on arbitrary 3d surfaces.

But instead we have the world we have. All advertising must follow the dictates of a giant all-powerful global corporation. Mozilla is trapped in a pseudo-C++ mindset and spending most of its efforts trying to reproduce the intractable mess of decades of CSS hacks, in the time the engineers have left after going through in excruciating detail all of the possible ways to 'borrow' memory. CSS, a brilliant system that is a pain the in the ass not only for programmers but also designers, so complex that only two computer programs in the world are known to do a reasonable job of rendering it accurately.

Its time to stop dragging the old tools, mindsets, and technical debt forward. Stop judging things on the basis of momentum or authority (Google/Mozilla/Microsoft) and start using your brain to select things rationally.

Mozilla as an organization is not going to be capable of admitting they made a mistake with Servo/Rust and recoding it in Nim. Just like the world is not going to accept that we should throw out CSS and use any other simple system that can reproduce graphic designs. And we are not getting rid of JavaScript with its horrible threading model and garbage collection anytime. But we should. In a sane world we would learn from our mistakes and throw all of that out.

Re:Writing a website in Rust by pcwalton on Saturday May 30, 2015 @01:23PM (#9630871)
> The very first design decision/belief they made was "no code can perform with garbage collection". Well, garbage collection does cause quite a few performance problems, but that doesn't mean it can't work if you engineer it right.

That's not Rust's philosophy. Garbage collection is great—when it makes sense to use it. Rust is designed to make garbage collection optional, following the way systems software has been designed for decades.

> Mozilla as an organization is not going to be capable of admitting they made a mistake with Servo/Rust and recoding it in Nim.

I've already gone over multiple times why Nim would not be a good fit for Servo (which is not to say that Nim is a bad language, just that it would not be a good fit for Servo).

Re:Writing a website in Rust by viraptor on Saturday May 30, 2015 @01:18PM (#9630854)
If you're going to write a block of text like that, you could at least fact check the main premise. Rust had GC. They started off with GC, so it wasn't the very first decision that "no code can perform with garbage collection".

Here's a post about removing GC from core rust 2 years ago: http://pcwalton.github.io/blog/2013/06/02/removing-garbage-c...

Next: they didn't kill GC. They removed it from core, because rust is capable of having gc implemented as a library. Standard library still has two gc-enabled pointers - Rc and Arc. You can use them in current code to have garbage collected values.

Re:Writing a website in Rust by filsmick on Saturday May 30, 2015 @01:27PM (#9630883)
Rc and Arc aren't exactly GC types... they are just reference-counted pointers, Rc being akin to C++'s shared_ptr. I get that in a sense, this is garbage collection, but certainly not full-featured like the ones you find in other languages.
Re:Writing a website in Rust by pcwalton on Saturday May 30, 2015 @01:36PM (#9630929)
You can use full GC in Rust--we use the SpiderMonkey GC to collect Rust DOM objects, for example. It's not the most easy-to-use thing, however.

Most systems software gets by fine with a combination of thread-safe and thread-local RC. Reference counting is a form of garbage collection that works really well when it's used only for the subset of data that needs GC--which is the style that Rust encourages anyhow.

Re:Writing a website in Rust by ilaksh on Saturday May 30, 2015 @02:08PM (#9631103)
Hmm.. Rust was created to support the new browser, browsers mainly manage DOM objects.. I wonder why you are using a legacy garbage collector in order to handle primary tasks rather than having that part of your core design?
Re:Writing a website in Rust by kibwen on Saturday May 30, 2015 @02:48PM (#9631286)
SpiderMonkey's GC is very modern, it's not legacy at all. Furthermore, while Servo influences the design of Rust, it does not dictate the design of Rust (or else, for example, Rust would have had struct inheritance years ago).
Re:Writing a website in Rust by viraptor on Saturday May 30, 2015 @02:20PM (#9631166)
Spidermonkey uses generational gc with some kind of compacting these days. Why do you think that's legacy? What models are strictly better than that?
Re:Writing a website in Rust by ilaksh on Saturday May 30, 2015 @02:35PM (#9631226)
Nim's garbage collector is better than Spidermonkey's.
Re:Writing a website in Rust by Manishearth on Saturday May 30, 2015 @02:44PM (#9631263)
Irrelevant here.

For Servo we need a javascript engine. We're already using Spidermonkey. It has a GC for Javascript; we're already paying those costs. The Rust-side representation of DOM objects is also managed by the GC; that makes sense because these are tied to Javascript things.

We don't use the GC elsewhere. I think at some point we did, but the only place now in Servo where GC is used is where the data is strongly connected to data already managed by the SM GC.

Nim's GC is for general-purpose use in a language. Spidermonkey's GC is for GCing javascript, which already has an extensive runtime (which the GC ties into heavily). "Nim's GC is better than Spidermonkey's" is a statement of no value (and oversimplifies the situation) unless the context is specified. Using the SM GC to collect random Rust objects would be a bad idea. Somehow rigging up spidermonkey to use a Nim-like GC in Rust (all other things being the same) would also be a bad idea. Two different scenarios, two different GCs.

Re:Writing a website in Rust by pcwalton on Saturday May 30, 2015 @04:44PM (#9631685)
No, it's not. Generational, incremental, precise GC generally outperforms non-generational, non-incremental, conservative deferred reference counting.
Re:Writing a website in Rust by Ygg2 on Saturday May 30, 2015 @02:23PM (#9631171)
Because rewriting Spidermonkey is both tedious and doesn't benefit from Rust safety guarantees.
Re:Writing a website in Rust by steveklabnik on Saturday May 30, 2015 @01:33PM (#9630915)
Refcounting and tracing are two different forms of GC, but you're right in the sense that most people mean tracing.

At the same time, we're putting a lot of thought into how to properly add an optional tracing GC. It's important that it doesn't impact the no-GC case, which is still, of course, primary.

Re:Writing a website in Rust by filsmick on Saturday May 30, 2015 @03:03PM (#9631364)
I'm glad to know there is ongoing work on a tracing GC. Rust has many strengths aside from lifetimes and ownership (algebraic data types, sane generics, strong module support, very strong type system), so a few features to make it more usable for use in contexts where performance isn't as important as expressivity would be very nice to have.
Re:Writing a website in Rust by Jweb_Guru on Saturday May 30, 2015 @03:21PM (#9631434)
IMO, "contexts where performance isn't as important" aren't very relevant to Rust (hence why I'm strongly against, for example, hardcoding a global GC into the language, or splitting the language into a GC'd and non-GC'd half). But I do understand why some people would like to use the same language for all these use cases, I suppose.
Re:Writing a website in Rust by Rusky on Saturday May 30, 2015 @06:18PM (#9631976)
I don't think the primary use case for a GC in Rust would be "contexts where performance isn't as important" so much as another tool for lifetime management.

The current reference counted types don't just get used for convenience, they get used because they describe the actual life cycle of the data they contain. A tracing GC would be similar.

Re:Writing a website in Rust by sinistersnare on Saturday May 30, 2015 @09:44PM (#9632665)
Actually, std::shared_ptr is more like Rusts Arc type, because std::shared_ptr is atomic, and Rusts Rc is not.
Re:Writing a website in Rust by viraptor on Saturday May 30, 2015 @01:44PM (#9630969)
I have disagree. I know what you mean in practice - the GC is not the default and some types will always be different. But reference counting and types with destructors is a valid implementation of GC.

Gc is "just" an automatic memory management. Rust is not a garbage collected language, but it does have optional garbage collection available.

Re:Writing a website in Rust by wtetzner on Sunday May 31, 2015 @07:04PM (#9635946)
Nim's GC uses reference counting, so I'd say it's a least a fair comparison: http://nim-lang.org/docs/gc.html
Re:Writing a website in Rust by ilaksh on Saturday May 30, 2015 @01:24PM (#9630874)
Ok thanks. It was not the first decision then, just one of the early main design decisions. I edited the text to reflect that.
Re:Writing a website in Rust by Tuna-Fish on Saturday May 30, 2015 @04:49PM (#9631704)
It was not an early main decision. Rust has been actively developed for a full decade now, GC was removed from stdlib 2 years ago.

The decision was only done at the point when the devs were confident that the ownership/borrowing system could manage all the normal workloads done by GC, and that GC could now be implemented well into the language as a library.

Re:Writing a website in Rust by ndesaulniers on Saturday May 30, 2015 @06:58PM (#9632144)
You're getting downvoted because people who have spent a lot of time engineering and building don't like it when people drive-by with hypotheticals. You have some neat ideas; show us we're wrong by writing code and profiling. Not claiming that something that was published earlier this week (gittorrent) is how the web (going on 23+ years) should be rearchitected. Claiming you don't get along with others doesn't give you a free pass to shit on other people's work.

As a side note; it's really easy to see the wrong in things. It takes more work to try to find the good in things. You might find that you're better able to connect with people by being more optimistic.

Re:Writing a website in Rust by filsmick on Saturday May 30, 2015 @01:24PM (#9630879)
While I agree with some of your arguments, namely that "popularity and merit are not the same thing", I think saying that Mozilla is "trapped in a pseudo-C++ mindset" and that its new browser would ideally be written in Nim is plain wrong.

The fact that using Rust to write a simple website isn't very handy doesn't mean it's a bad language. Web development simply isn't its primary focus: this is a systems programming language we're talking about. The mere fact that it is being considered for writing web apps is impressive since Rust is supposed to be a better C++, not a better Ruby, Python or Node.js. Rust mainly emphasizes performance and safety. This means all the 'magic' that happens in a dynamic language is exposed to the programmer, and has a cost: the code is more verbose, and seemingly simple things are more complicated.

Re:Writing a website in Rust by ilaksh on Saturday May 30, 2015 @01:32PM (#9630903)
The idea that you can't get something good without a trade-off involving something bad is a false belief, an over-generalization that is very popular among people from all walks of life, including, unfortunately, technologists. Trade-offs do exist, but even a sword in fact has many more than two aspects.
Re:Writing a website in Rust by pcwalton on Saturday May 30, 2015 @02:37PM (#9631236)
OK, but we know precisely what the downsides of GC are (for some applications).