12 ms·
So I've just tinkered around a bit in Rust, and I'm not intimately familiar with the language. My experience has been pretty good, but I don't see how it's a go
by cjpearson 5y ago
So I've just tinkered around a bit in Rust, and I'm not intimately familiar with the language. My experience has been pretty good, but I don't see how it's a good fit for the web domain. At least not the enterprisey, CRUD, business apps I'm used to building.
I'd be curious to hear from people who have been using Rust for their web backends, though. Beyond the classic selling points of speed and safety, what benefits have you found that apply to web development? Have you had any issues with the ecosystem or finding developers?
- nine_zeros 5y agoIt helps in RDD (resume driven development)
- jkelleyrtp 5y agoThe DB space for Rust is a bit young, though there are several good projects like sqlx making it much more pleasant. Rust shares many of the benefits of Go: - statically linked binaries for ease of deployment - good concurrency - builtin testing framework But it's a much sharper tool than Go: - Really great error handling with Result/Option and the ? marker - Like, really really good error handling, esp compared to Go - Very pleasant logging and tracing - Serde is fantastic at automatically serializing/deserializing datastructures - Generics make Map/Reduce/Filter really easy and readable - Really good project management through modules/Cargo.toml - Crates.io is like NPM - really discoverable and easy to upload (with its goods and bads) - FFI with Swift, C, C++, Node, etc to share code everywhere - Builtin documentation - Builtin benchmarking - Powerful hygienic and non-hygienic macros There's a lot more. I would say people choose Rust over other web frameworks not because of the language, but the emphasis on great tooling. Being able to test, document, benchmark, deploy, package, with a language that feels like a child between Go, JavaScript, and C++ is very attractive. Plus, it's fast - like really fast - and it's really obvious where optimizations can be made when the time comes. I've worked a decent amount with Go, but I'm also frustrated with the size of projects balloon. When I compare my Rust and Go code, the Rust code ends up being much smaller (LoC) and much more dense/terse. I've been working with it for a few years now, and I'm 100% willing to trade some complexity when doing Advanced Stuff (tm) for the 1st-class tooling. I hate having to decide which testing/documentation/building/benchmark/etc framework to use in other languages. I just want to build, not futz around with Jest/Babel/Webpack/Poetry/PyEnv/Opam/CMAKE etc. If you're looking into using Rust for web, I recommend https://github.com/http-rs/tide https://github.com/http-rs/tide - it's the most pleasant web framework I've ever used.
- rob74 5y ago> When I compare my Rust and Go code, the Rust code ends up being much smaller (LoC) and much more dense/terse. Yes, but is it more readable too? The obfuscated C contest also tends to produce a lot of dense/terse code, but you probably wouldn't want to use that in a production system...
- cjg 5y agoIn my experience, Rust code is relatively easy to read, even by developers with no Rust experience. Of course, you can write hard to read code. But that's not typically what comes out of a process of writing production software. That's not to say that someone with no experience will fully understand the ownership transfer & borrowing that's happening, but that's just stuff you need to do for the compiler. Reading code that already compiles, you can mostly ignore that and focus on the program logic.
- cogman10 5y agoYeah, readability is high, it's writing that can be a bit harder IMO. Especially for someone unfamiliar with rust, it can be hard to really know why someone is using self, &self, or &mut self. Yet the code reads the same. That's the funny thing about rust.
- zozbot234 5y agoThe compiler is supposed to tell you when you get it wrong. This does leave design issues on the table, but it's also good for those to be addressed explicitly, by the more senior people on the project.
- Thaxll 5y agoRust is one the hardest language to read. Take two people that never used Go or Rust and make them read code, good luck with Rust.
- 5y ago
- zozbot234 5y agoIt's a bit early for Rust to be widely applicable to web development, because common web backend frameworks require nightly Rust which is not appropriate for production. But most of these nightly dependencies are being resolved.
- roblabla 5y agoThat's no longer the case. There are many web frameworks working on stable, and Rocket, which was one of the most popular nightly-only backends, has been building on stable for nearly a year now!
- paavohtl 5y agoWith the caveat that you have to use _nightly_ Rocket straight from GitHub (but still stable Rust, which is definitely preferable).
- zozbot234 5y agoThey're working on it but they don't have an actual released version that works on stable Rust. So you'd end up having to pick stable Rust or stable framework, which is not great.
- steveklabnik 5y agoWe are building openapi-based stuff in Rust at Oxide, and my coworkers gave a talk on the hows and whys: https://www.youtube.com/watch?v=EmSjZbSzA3A https://www.youtube.com/watch?v=EmSjZbSzA3A One thing I hear from people more broadly is that Rust’s lower resource usage, in today’s cloud based environments, translates directly to bottom-line savings. It’s not so much speed directly as it is less CPU and memory utilization, letting you do more with less. That matters when you’re paying for what you use.
- riquito 5y agoThat was an interesting presentation, thanks for sharing
- cjg 5y agoWe are using Rust for backend web development and other things. For us, the safety is the critical reason to choose Rust - particularly the thread-safety. Also the relatively small memory footprint compared to something like Java. Performance hasn't driven our decision at all - the number of requests per second is very low. It's correctness that matters. We are a bit unusual because customers have locally deployed servers rather than servers managed by us, so bugs are harder to fix. We haven't hired any developers specifically for their Rust experience, but have instead trained internally and now have a group of about 10 Rust developers working across a couple of projects. I would say that training like this has been relatively straightforward. One of our hires, a recent graduate, had some existing Rust experience with personal projects, and this was particularly beneficial in helping the team to bootstrap. The ecosystem is surprisingly mature. Async is probably still shaking out somewhat, but that's moved on hugely in the last couple of years, and we haven't had any particular problems. Overall the experience has been hugely positive. The biggest barrier to adoption, in my opinion, is that people are scared of learning Rust because it has a reputation as being difficult. I don't think it's any harder to master than some other major languages such as C++ or Java - although perhaps you have to understand more at the beginning: ownership and borrowing are right in your face.
- brundolf 5y agoWhat web framework do you use? This to me seems like the part that's least-baked at this stage. Iron doesn't support async if I recall correctly, actix supposedly has a complicated mental model and was mired in drama last I checked, and Rocket looks promising but is still in the somewhat-early stages.
- mdtusz 5y agoCheck out tide. It's still very early days for it, but is in my opinion the easiest to use and I'm betting in the long term will win out as the "express" of the rust world. It has very straightforward routing and middleware semantics which covers the majority of the "base" needs for most web server backends.
- cjg 5y ago
- phibz 5y agoI implemented a simple blog and resume personal web site using rust. I did it mostly as an exercise. I tried just jumping in and had a lot of trouble. I needed to go back and read the rust book. What I found was relatable to what I knew from Scala and C++ but definitely took some effort to learn compared to something like golang which I picked up in a week. I built using actix 1.x, serde, chrono, rusqlite. I originally tried diesel but it doesn't support certain relationships that are common in SQL. I made my own traits for common CRUD and ORM patterns but I'm not happy with the amount of boilerplate code needed to implement them. I could clean them up with macros but I'm still rethinking the approach. I did implement my own (unpublished for now) crates to output jsonapi formatted messages and handle uuid primary keys in sqlite, serde from the DB and json. Overall I'd say it's comparable to coding a web app with C++, but perhaps more straight forward. I added my own middleware for Google Auth without much trouble. It definitely seems to be a "if it complies it works" type experience.
- pjmlp 5y agoCoding a web app with C++ Builder is like dragging stuff into forms, VB style.
- programmarchy 5y agoRust has one of the best toolchains for Wasm.
- gameswithgo 5y agoIf you were coming from Python/Ruby then the speed boost of Rust might seem like it is worth it, but if you are coming from Java/C#/Go/F# I agree it is a hard sell for a normal web back-end. But if you have one that is compute heavy, it could be a great fit. If you want to use mostly WASM on the front end, it could be a great fit as well. Don't have to ship a runtime with your wasm, and can share code.
- staticassertion 5y agoRust makes working with data easy. 'serde' is insanely good, so right off the bat if you're messing with formats like JSON you're going to have a best in class library. Concurrency is pretty trivial as well with async/await and tokio. Really good libraries like tracing, tonic, etc. Plus the tooling is really strong. Package management and building is easy, static bins, etc. I run a company that uses Rust and hiring isn't hard - it's an advantage. We get really great people who are looking for a place that uses Rust. Or we just train people up - it's not a very hard language.
- EugeneOZ 5y agoI’ve been using Rust for 5 years for REST API and the most important thing is the safety of refactoring. Not memory safety, not speed, but errors handling and safety of refactoring are key features for web backend. Also, things like Cargo and ootb testing framework - are quite valuable.
- _Kobo_2207_ 5y agoBoth matureness of the ecosystem and developers are a big issue. For typical enterprise apps you just don't need the characteristics of Rust and therefore it doesn't make any sense to pay the penalty for using it. If your focus are business logic related needs (as opposed to best in class performance, no GC, etc.) using Rust is a grave mistake. Just use boring Java or better Go (better tooling, standard lib and scaling) and focus on delivering value to the customer.
- justsomeuser 5y agoI use Rust because the program I am writing mainly maps types from type A to type B. A dynamic language has no clue what these types are so you find out what you did wrong by refreshing the app at runtime. In Rust it tells you instantly, so it reduces the iteration time. Many web apps fit this “map data from A to B” domain, so having a specification for types A and B and getting the compiler to check all variations seems like it would save a lot of dev time. Out of the type systems available I like Rusts best as it seems to map well to JSON using its enums feature to represent null or polymorphic types. But you need to pay the learning curve of Rust, which I am still not sure it is worth it.