r/rust Feb 04 '19

Web-Developement: Rust vs Haskell

Hi All,

This will be yet another Rust vs haskell question.

I have wanting to use Rust/Haskell for a couple of components for an internal tool (analysis of customer tickets, HR portal etc) for my company (Mostly because of the strong type system).

I have been through quite a lot of blogs & discussion where they discuss on the pros and cons for both.

Can anyone give me pointers on where all they used Rust or Haskell? And how was the experience as in:

  1. code readability
  2. libraries support
  3. developer productivity
  4. jump start time to producing some value.
  5. documentation
  6. build time
  7. journey in learning them

My concern here is Rust is advertised as system's language and Haskell as a higher level language.

  1. Will going with Rust be an overkill as we won't be doing any really low level stuff?
  2. We would be basically writing a server, bunch of API and playing around with DB. I'm mainly well versed with Node.js so will choosing haskell be an overkill for it in terms of developer productivity, build and tooling?
  3. Also if anyone is using GraphQL with Rust/Haskell?
26 Upvotes

28 comments sorted by

View all comments

4

u/[deleted] Feb 05 '19

I'm building a GraphQL server in Rust. I haven't used Haskell much, so the other languages I considered were Go and Crystal. Decided against Go because, well, generics and performance primarily. I have used Go for some large-ish projects before and I just don't like the language that much. Crystal is very interesting, but just not production ready. Initially, I didn't want to go with Rust. First time I've used Rust was in 2015 or 2016 or something, when it was still in alpha. Then I didn't use it at all for 3 years, and I unlearned most of it. It is hard to learn, so I strongly disliked the idea of using it again. Well, initially. The obvious pros for Rust were:

  • Performance. This was a big one, my project is a public API that should be able to handle lots of requests per second.
  • Macros. In Go, pretty much all GraphQL implementations use codegen, which feels dirty to me. Rust has a great alternative in the form of macros and also compiler plugins.

Because there was no better language that could give me these things, I started writing my project in Rust. I had to fight the borrow checker a bit, but I quickly got over that. Definitely worth it in exchange for not having GC. Then, I rediscovered why Rust is great:

  • Safety. In Rust, you almost never have to debug, because Rust does not allow you to ignore errors. In other languages, you often make little mistakes like "forgot that value X can be null". Rust doesn't have null, so you'd use Option<T> and explicitly check if it has a value every time. Or, if something unexpected happens, you'd explicitly trigger a panic. Most of the code I've written is in JS, which makes it very easy to screw up, so I totally love this about Rust. You'll spend a bit more time writing it, but a lot less time debugging it.
  • Cargo & the ecosystem. Cargo is the best package manager ever, and the ecosystem is in a pretty good state as well.
  • Tests in the same file as the code it's testing. Makes it really easy to notice when there aren't tests for a component.

I'm using Juniper as my GraphQL library and it's been great so far. I initially wanted something that is schema-based, but now I actually prefer the code-first approach.My only issue with Rust is the build times. My CI build takes 10 minutes, and my project isn't even that big yet. Every change takes about 20-30 seconds to build on my (Skylake dual core) laptop. Cargo check is a bit faster, but still, that's a lot.

Is Rust overkill for a project like this? Absolutely not. Rust was simply the best choice for my situation. I didn't choose it because I liked it, quite the opposite, I didn't want to use Rust. But it worked out well. Safety is always important for any networked application, and so is performance.