1) Why rust? 2) Why web server?

Hi, I'm a noob just seeking general information. These two questions may seem "adversarial," but they are not meant to be in any way. They are just honest, curious questions.

  1. I understand that rust was created to be a '"systems programming language" (of course I know it is general purpose and can do anything). I understand that a better systems programming language than c++ is desirable. But why develop rust over using, for instance, haskell? Is haskell not considered low-level enough, or fast enough, for systems programming (I honestly don't know)? Could haskell not have been used to write servo (again, I honestly don't know)? Disclaimer - I'm not a haskell programmer or fanboy, I just figured one of it's selling points was 'safety' similar to rust, and it is certainly better than c++, so....

  2. I noticed that there was at least one web server already written in rust (probably more). I know why web servers are written in other languages. For instance I do a fair bit of programming in erlang. I use an erlang web server because I need a web server that can embed in erlang. Similarly I did some programming in clojure once and I used a clojure web server because I needed something embeddable in clojure and something that could be programmed in clojure. But you don't "embed" stuff in rust... do you? It just compiles down to machine code, right? There is no run-time or virtual machine, and it isn't as if rust would "script" a web server either, would it? So why not use apache or... [insert whatever server name here]? Or perhaps the approach is that you compile the rust web server code along with your own custom code to create your custom web server? If that's the way it works... yeah, I can see why you'd want something like that.

In closing, I'd like to state that I'm actually the last person to think there are too many programming languages. I probably know two dozen programming languages, and am pretty much a "programming language aficionado." These are just very basic preliminary "curious" questions I have before looking into yet another one.


For one, Haskell is anything but low-level. It is a beautiful language, but it has an execution model that is completely at odds to what you'd like in a systems language. I'm not saying it isn't the way of the future (maybe it is?), but today Rust shows you how to successfully combine some of the cool features from FP with the basic "I know how this is executed".

In systems code (let's say a kernel) most of the functions by far would have to be IO typed, so that Haskell would just be used like a second-class imperative language.

Also, Haskell cannot run without a runtime. For a "true" systems language, that is out of the question (Rust step-by-step removed the runtime it once had to get to this state).

I guess that one valid reason is "because we can" :smile: Also, writing and benchmarking a web server is a relatively common (because real-world inspired) way to measure performance you can get out of a language or a particular programming technique. And right now, a lot of effort has to be put into proving that Rust really can be as fast as, say, C++ for such tasks.

1 Like

Got it, and totally understand. I had considered these reasons, but wondered if there was another reason I hadn't seen, or some way to use the web server embedded in rust or whatever. Any reason is valid, I just wanted to know what it was :smile:

I don't know about others, but the reason I decided to write a web server library in Rust was not just "because I can", but because I wanted to have one and also to see if it's a good idea. I had been using Rust for personal projects for a while and I thought that it would be a nice language for such a relatively complex thing as a dynamic website (not just serving static files). I had become tired of runtime errors, dynamic types and "smart" coercions, and Rust usually gave me the feeling that my programs would do what I told them to do (once they compiled). That's why I thought that Rust could be suitable for a web server.

I think that it's still too early to say how suitable it is, but I guess it's about as good as using Java or C# (except for the obvious lack of tools, due to Rust being new). We need to do more experiments :smile:

Being low-level means that you will (or, you must) instruct the hardware in a very detailed manner. High-level languages usually hide the details to make your life easier. Compilers and interpreters will take the responsibility.

However, while compilers are extremely sophisticated to make your program performant, and they do better than humans do in many cases, there are still the cases that compilers don't optimize well. For example, whether to put your data in a heap or in a stack. Haskell is no exception, and in fact it is much higher than ordinary languages. Its compiler does its job incrediblely well considering its high-levelness, but it's still hard to write a program that matches C's performance in Haskell.

Note that I said "hard". It is hard, not impossible. Actually there are some Haskell programs out there that are truly as fast as C programs. However it's even harder than writing fast C programs, as you should use various tricks to get closer to the hardware. That's why Rust was needed to create Servo.

Yes, probably Rust and Haskell are the two which primarily advocate safety as one of their selling points. However, at least limited to memory safety, there are many languages that are just as safe as Rust, thanks to garbage collection. Safety just became so normal that nobody explicitly claims it. What differentiates Rust from them is that Rust achieves memory safety without relying on garbage collection. That's why safety can be a major selling point of Rust. C and C++ take performance, whereas Java, Haskell, Python and so many languages take safety, but Rust has both.

Similar to this. A typical Haskell web application is compiled directly with the Haskell HTTP libraries, forming a standalone web server. Then, some "real" web server like nginx sits in front of it and acts as a reverse proxy. This way you can host multiple applications (which are web servers themselves) with a single nginx instance. Rust does the same. There are already web sites written in Rust, including https://crates.io/ and (shameless plug here) http://homu.io/ that I'm maintaining.

And so why? Why should you write a web application in Rust? Actually, for me, there's no real reason. Web programming is not a field that requires extreme performance that Rust is specialized at. Haskell or Erlang would be sufficient. But the thing is, I just like writing Rust code. I like its strict type system. I like its naming convention. I like its endorsement on exception-free code. I like its aggressive deprecation. I like to see the compiler messages that try their best to help me. I like its sane defaults. I like its community. I even started to like its pervasive curly braces! :stuck_out_tongue: (I've programmed Python for more than 10 years, so curly braces had seemed obsolete to me.)

So, it would be awesome if I could use Rust in my web applications. That's why I'm continuously investigating web programming in Rust. Some day, http://arewewebyet.com/ will be full of tables filled with green!


me too, very much

An innovation, no doubt. Definitely worthwhile. Also, the approach to concurrency safety.

Sure, I always understood why you would want to write a web APPLICATION in Rust. I just didn't know why you'd want to write a web SERVER in Rust (since a plethora already exist written in C). I didn't know that writing the web server in Rust would give you the ability to write the application in Rust. But you explained that it works like I theorized (compile the server along with the web app), so it makes perfect sense now :slight_smile: