8 ms·
I know Rust is very popular right now but as a back-end dev I always wondered what's in it for me. I never had to write programs where garbage collection was a
by vvpan 4y ago
I know Rust is very popular right now but as a back-end dev I always wondered what's in it for me. I never had to write programs where garbage collection was a problem and learning a whole new paradigm (borrow-checking) just seemed unnecessary. And it seems like it is a language that is more difficult for junior developers than almost any other one. What does Rust solve for the casual user?
- jtwaleson 4y agoDefine casual user :)
- wofo 4y agoPersonally, I'm finding myself reaching for C# to solve most problems I come across. Rust is appealing to me on a more theoretical level (or when there is a domain where it truly shines, such as concurrency or C-like performance). IMO the strengths of the language are not a deal-breaker for a casual user (e.g. someone writing CRUD or line-of-business applications)
- stusmall 4y agoSo I deeply love rust and it's my goto even for applications that it's not especially well suited for. I just know it well and it's easy and natural to work in. It's a flexible language so it plays well in a lot of use cases even outside the ones it excels most at. With that said, it's okay if there isn't much in it for you. If it doesn't sound useful for your current use cases, that's okay. Don't use it. Use things because they are interesting and fun or because they make your life better. Don't feel the need to use it just because it's on The Orange Site a lot.
- SomeoneOnTheWeb 4y agoMany reasons actually. The tooling is excellent (builtin package manager, test suite handling, etc.) The language itself is also very good in that it prevents you from doing many mistakes you'd do in other languages. It's hard to show an example when you don't know Rust at all, but usually Rust programs tend to have less bugs than others. That being said, there are also downsides - apart from the steep learning curve, compilation is pretty slow and the language itself isn't as good as some others for prototyping - if you make something simple and want to go fast, then maybe TypeScript will do a better job, despite its numerous problems. Rust is more about robustness and correctness (and performance of course). If these are not appealing to you, then sure some other languages like Java, Go, C#, TypeScript or others can do the job.
- OkayPhysicist 4y agoRust is very much not a replacement for writing a program in a language that would have a garbage collector. It's main niche is making C++ obsolete, so categories where either resources are limited due to there just not being a lot of resources available (embedded) or are limited due to you needing to squeeze as much performance out of your machine as possible (OS, drivers, numerical computing, maybe someday video games). It's probably not a good first language, but neither was C++: that's not its niche.
- mattrighetti 4y agoDon’t forget about WASM
- elcritch 4y agoEven for embedded and other systems programming context automatic memory management via ref-counting systems can perform as well or sometimes even better. I found non-atomic ref-counting to be fine for embedded. For truly small programs I'd rely more on compile time computations which Rust isn't actually great at vs Nim or Zig, or a bunch of others. Actually both C++ and Rust tend to make heavy use of reference counting via `std::shared_ptr<T>` and `Rc<T>/Arc<T>`, respectively. Personally I think that while Rust's borrow checker is nice for some cases and does encourage fast/efficient memory usage, it's also overkill vs automatic memory management for even most system or real-time programming. Especially as compilers get better and can remove 90% of the reference counting spots.
- steveklabnik 4y agoI have never used Arc<T>/Rc<T> in my embedded work, and rarely in my non-embedded work.
- elcritch 4y agoAh true, I probably overstate the amount of Arc<T>/Rc<T> in Rust code. C++ uses shared_ptr<T> a lot in the code I've been dealing with lately, so maybe its biased me. Though it's partly up to the skill/experience of the programmer too.
- Ygg2 4y agoNot using Rust is also OK. I don't know Rust web stack enough, but my impression it's sometimes used to reduce AWS cost and decrease latencies, with some success. But doing a rewrite requires Rust programmers and they hard to hire.
- the__alchemist 4y agoRust is my favorite language for embedded and writing desktop programs, including 3d graphics. For backend web dev: Skip it. I prefer Python/Django.
- hardwaregeek 4y agoThis is a vague sentiment so it’s okay if it doesn’t mesh with you, but I like Rust because it’s a great example of language design done well. I’m not claiming Rust did everything right but I’d say it’s a great example of programming language design that manages to balance theory, practice, user experience, tooling and safety. I think any developer can learn a lot from Rust’s design. Including what not to do! Also it’s just plain fun sometimes. I love expression based syntax where you can assign to an if or have a block result in a value. It just feels delightful. The standard library is very constrained but within those constraints it has a lot of wonderful depth. Functions like split_once or unwrap_or_else are delightful to use. It gives me that same feeling as Ruby where the language feels designed to have you enjoy writing code. The language has all of the requisite tools I want to model data structures including tuples, structs, and enums. It’s great! Try it out and see for yourself
- mattrighetti 4y agoLearning (and I still am) Rust was great for me. I feel like it teaches good practices that you can also use in other languages and also it forces you to understand “how things really are working underneath”. That’s why it’s hard in the first place, but don’t put it in a corner just because of that.
- BlackFly 4y agoI like rust, but wouldn't recommend it in my enterprise shop. I don't know what language you are used to, so I will suggest some things that you might enjoy learning about. In languages without spread operators (like java), immutable objects are quite clumsy to work with: I want this same object but these two fields changed (like the replace method on python's named tuples, but those are also annoying...). But with mutable objects, everyone can mutate: chaos. Rust gives you the mut keyword, structs are immutable by default. Ever wanted to implement a method on a class in another library that just used the public API? Just make your own Trait in rust. Ever wanted to make sure that someone would call `close()` on your implementation? Ever wanted to make sure that no one would use the object afterwards? That's garbage collection of a resource that isn't memory, most GC languages won't manage that for you, but the borrow checker will. Pattern matching, algebraic data types, expressions and statements distinctions, an excellent build system, procedural macros, no null, no exception handling, good type inference; none of these are new or unique to rust, but lots of languages lack a few to many of them. But yeah, some times I don't want to decide between monomorphisation via generics, or heap allocating for dynamic dispatch. Some times I just want a JIT and a garbage collector to take care of that for me. But that is another thing rust might give you: a newfound appreciation for what you have.
- kaba0 4y agoJust a heads up, something like that spread operator is actually coming sooner or later to java: https://github.com/openjdk/amber-docs/blob/master/eg-drafts/reconstruction-records-and-classes.md https://github.com/openjdk/amber-docs/blob/master/eg-drafts/... Pattern matching (for records) is already a preview feature.
- yobbo 4y agoSo it has a steep learning curve and it's not the "best" choice for people's first couple of projects. But, before you can make anything meaningful with a language, you have to first make many toys. That's the rationale for using it in cases where there are better alternatives. (To make you comfortable using it when there is a need for it.)
- steveklabnik 4y agoIt’s hard to say without knowing what exactly you’re comparing it to. Because I already know Rust, and prefer it as a language generally, it’ll be my default choice, just like you have your default choice. It works well for many cases in the backend, but not all of them, like lots of technologies. If you don’t find a compelling reason to switch, you shouldn’t!
- mjr00 4y ago> What does Rust solve for the casual user? If by casual user, you mean the 95% case of a back-end developer whose main job is pulling data from various sources, performing operations, and placing that data elsewhere and/or displaying it to an end user: nothing, really. Rust excels at performance, but the bottleneck in modern web apps is going to be IO, whether that's loading data from a database or from a third-party API you're integrating with. Rust excels at correctness, but your errors are going to come from bad data and system outages which require manual intervention anyway. Rust excels at security, but if you're using a GC language running on a Docker container on an ephemeral cloud instance, the kind of security Rust provides isn't a likely attack vector for you. All that being said, Rust is a great language! It just has its niche, and that niche is not the typical web-dev back-end work that most developers do these days. As others have said, you'd use Rust in the same situations you'd use C++: building a database, building a web server (like nginx), etc. If you're just building a web app that talks to a database and serves HTTP responses, stick with Python/Ruby/Go/PHP.
- steveklabnik 4y ago> but the bottleneck in modern web apps is going to be IO This is true in some senses, but also, response latency isn't the only thing a web application does or is evaluated by. Many applications have, for example, background jobs, that do arbitrarily complex processing outside of the request/response cycle. Additionally, people who write web services in Rust talk about decreased memory usage, consistent memory usage, and lower CPU usage. In a cloud context, that can translate directly to revenue saved, by spending less. If that tradeoff is right for you depends on a variety of things, of course. "speed" isn't the only relevant metric that you may want to optimize for.
- cogman10 4y agoDon't forget startup and distribution time. It's not terribly hard to have a scratch rust container which is about as slim and secure as you can get. That container will startup pretty much instantaneously even if it's cold. You are looking at ~5mb container vs 200+mb if you did a jvm based container. It's probably overkill for most applications and companies, but it's something to keep in mind if you need fast scaling for cheap.
- stjohnswarts 4y agoIt's completely okay for rust not to overlap much with your work. If you aren't doing a lot of systems programming type jobs it's probably not all that applicable to your day to day work. If you're interested in systems programming then you might look into it. Seems like Java or typescript or ruby|python|php would be more up your ally and I assume you know one or more of those as a part of your work.
- worik 4y agoThe replies here are all good. I would add... A feature of modern computing is the use of very low power systems (I programme mostly for Raspberry PI - not very low power) and/or systems run on "pay as you go" platforms which can scale hugely. Rust is very efficient at run time. (Not at programming time nor compile time) so is very useful in these cases. A counter example, from my life, to illustrate: I ran a mail server for a group I was involved with. I spun up a VPS and Mailman. (Mailman v3 is built on Django/Python). I had to double the capacity of the VPS as 500MB of memory was not enough to install and run Mailman (I think the problem was at install time, but that made very little difference). The cost of my mail server doubled because of the inefficiency of the Django/Python framework. Django is very efficient at programming time, but is resource hungry. The original Mailman ran in 40k, the "modern" version was not usable on a platform with 500MB. For me it was no biggy. One server, $10 not $5 a month. Mēh! But if that were a million instances..... So with all the progress in computers getting more powerful the actual instances we use are getting weaker (for very good reasons). A language like Rust can be very helpful in this case. (On the Raspberry Pi I use Rust for realtime control of audio processes)
- hosh 4y agoOne niche platform is Sandstorm. Because of the way it is architected, a single “grain” is started up for a single document. So fast startup and small footprint is very useful, even if it is still a web platform. As much as I like Elixir, it wouldn’t do as well running within Sandstorm as something written in Rust.
- mlindner 4y agoHonest question, but I don't seem to understand the base context of what you're saying. If you're a backend dev, you care more about performance than a front end dev does. That's why backend devs generally write software in something like C or C++ where Rust would play in perfectly. However those languages have security issues and trade that off against performance Why would you say that Rust has no relevance to a back end dev when from my understanding Rust is THE perfect language for backend devs because it maintains the speed of C and C++ but adds security? What is the context that I'm missing?
- steveklabnik 4y ago> That's why backend devs generally write software in something like C or C++ There's tons of web applications that don't write backend logic in C or C++, but in a GC'd, possibly dynamically typed language.
- mlindner 4y agoIs it actually backend if performance doesn't matter? I thought that was one of the key differences between backend and frontend.
- steveklabnik 4y agoI see the split as an architectural one. Not every application has intense performance requirements.
- conceptme 4y agoThis is not my experience most backend uses php, ruby, python typescript, java definitly not c or c++ and most performance is usually gained by optimizing queries, adding indexes avoid doing work and caching. The low level libraries used in these languages do often use c, c++
- echelon 4y agoIf you write Rust + Actix/Axum for backend, you'll never even see the borrow checker [1]. Rust is quickly growing into Golang and Java's space for web services. My startup uses Rust in production for our web APIs, and we're really happy with it. [1] You'll probably need to spend a few hours learning the language basics, but it's really easy at this point with the docs and best-in-class compiler error messages.
- StreamBright 4y agoAs guy who has very similar background just like you: there is very little in Rust that will benefit your straight away. On the other side, you are going to learn a lot about low level details associated with systems programming (mostly influenced by C++ in case you are learning Rust). For me the biggest win with Rust is the performance that I can get out of it, which is irrelevant in most cases. If you work on a problem that requires extreme single node performance then you can learn Rust instead of learning C++. This is probably less than 10% of the use cases people use programming languages for. As far as teaching juniors: I had great success with Python, yet, a lot of foot-gun situations. With Rust I am not good enough to mentor our junior devs, so we learn together. It goes very slowly.
- satvikpendem 4y agoI have written another comment for a similar question, so I will paste that below: --- I'm not sure I agree with the article's premises. Rust can be difficult, yes, but it can also heighten developer productivity above other languages. In Go, I'd have to worry about whether I checked for exceptions via `if err != nil` everywhere, while with Rust, I can depend on the compiler telling me if I haven't done so exhaustively, via the Result type. Same for having algebraic data types or, well, generics in general. I will also push back on other commentors here saying Rust is not good for web apps and APIs, and I have found that to be the opposite of true. I read Zero To Production In Rust [0] (a great book by the way, all about creating a web API with actix-web and Postgres) and deployed an API that has not gone down a single time since deploying near the beginning of this year. It's as ergonomic as (and sometimes even more so than) any NodeJS or Go API I've made (as even though Rust doesn't have function overloading, actix-web and others have some macro magic they do behind the scenes to make it appear as if it does), and there were very few times I had to contend with the borrow checker. If there had been and if I were really going for speed, I would also have cloned everywhere that was needed. When I write something in Rust and it compiles, I can depend on it to work, and to continue working. At the end of the day, use the tool that makes sense for your business, but I don't think Rust was necessarily a bad choice based on my personal experience with it. [0] https://www.zero2prod.com/ https://www.zero2prod.com/ --- From: https://news.ycombinator.com/item?id=33714007 https://news.ycombinator.com/item?id=33714007
- maldev 4y agoIt doesn't. Use C#, Java, or even python. If you're low level and dealing with low level code and constructs, you're better off using C, or C++ just for the language features like templates. Rust is genuinely only useful for the niche application of a desktop application, that doesn't reach low level, but you need a bit more fine grain controls than C# or another higher level language will allow. For example, a web browser is like the ideal usecase for Rust, and it makes sense, since that's really where it's got most of it's teeth with Mozilla. I personally don't see why you would do something like Grep, in Rust, when C#, Python, Go, exist. But I do see like Unreal Engine or again, Firefox/webbrowser in Rust being nice.
- alephu5 4y agoGrep is a performance sensitive program, it's not unusual to scan through thousands of files and millions of lines so small inefficiencies are noticeable. If you tried this in python it would probably take hours to scan through something that ripgrep does in a few seconds
- burntsushi 4y agoPeople have written greps in Go and Python (and Perl), and they aren't even close in all around perf to GNU grep (written in C) or ripgrep (which I wrote in Rust). Maybe you don't know what you're talking about, despite coming across as certain of yourself.
- maldev 4y agoI'll write a simple grep tool right now in C# then and see what performance I can get. I'll get back to you when I finish.
- burntsushi 4y agoHere are your benchmarks to try: https://blog.burntsushi.net/ripgrep/ https://blog.burntsushi.net/ripgrep/ If you respond, please provide instructions to reproduce your measurements for a Linux machine. Why do you even have to write one in the first place? If C# is such a natural choice, why hasn't it already been done?
- BFLpL0QNek 4y agoMy day job uses the JVM heavily. I don’t have issues with garbage collection and don’t mind the languages to much. I’ve used a bunch of common languages, Python, JavaScript, Typescript, PHP, Bash, Go etc. Not so common languages such as Haskell. My first choice for personal projects is now Rust. The memory/borrow checking to me is just a nice benefit I get from using Rust, I don’t use Rust for the borrow checking. My main reason for Rust is while it’s not as high level as say Java/Python etc I find it is still at a nice level to work with and can be far more expressive with the enums, traits and generics. The second big reason I use it is my programs end up fast and efficient with little effort. The third reason is I can get tiny statically linked binaries that just run anywhere with no dependencies. Reasons two and three mean I can host my applications on the cheapest, most minimal resources available and still outperform other languages on more expensive hosting. Currently my choice is to stick the binary in a Docker image which ends up sub with a sub 10mb docker image then deploy on the smallest 128mb AWS lambda and pay fractions of a cent to host. Services that need to be long running go on the smallest $5-10 vps’s . The borrow checker can be a pain however I find the compiler error messages really helpful in it often tells you what you should do to fix the problem with plain English error messages and code suggestions.
- kaba0 4y agoYou might want to check out GraalVM’s native compilation. While this step will be slow, you can just use the JVM version for development and compile it at the end/CICD step.
- pjmlp 4y agoThe only caveat is that the compile times are still comparable with C++ and Rust, when Graal kind of analyses the whole world to produce a final binary. On middle range hardware, it appears to be the moment for a coffee pause, although it has definitly gotten better, specially with updated reachability metadata.
- fulafel 4y agoI think the popularity is helped by the fact that it's rarely useful in the day job for most people. You can have your Rust tinkering and there's a natural moat between it and work. It also automatically throws the safe and useful seemign borrow checker puzzles at you that don't involve the outside world.
- zozbot234 4y agoPretty sure it's the other way around - Python used to be something that was "not useful in the day job" and mostly about tinkering. This has changed dramatically over time, so Python is now a lot more popular.
- fulafel 4y agoPython used to be moated away from enterprise/corporate world as well, and this made Python loveable for the hackers & hobbyists before it went mainstream. So it's the same way around :) In Python's case the pull was different in quality, it was about a higher level more expressive language that could get more done faster compared to the estabilished corporate/enterprise languages.