6 ms·
A critical question first: why do I ever need Rust for web development? Typically a critical question at HN will get downvotes because it is not encouraging or
by synergy20 3y ago
A critical question first: why do I ever need Rust for web development?
Typically a critical question at HN will get downvotes because it is not encouraging or constructive or whatever, but that's OK as I really want to know the answer here. I understand Rust is cool for system programming, but I don't feel Rust is good for _everything_
Assuming you have some cash to make web related products, are you going to use Rust web framework at all? I know I won't.
- bryanlarsen 3y agoSurprised not to see this answer yet: To put a web interface on a rust program. Suppose you have a program that does something very much non web related but well suited for rust, like embedded, or heavy CPU calculations, high speed control, etc. And suppose you want to add a UI or API or RPC or Prometheus metrics or monitoring or etc to a program, HTTP is often a convenient way to do it.
- deleted 3y ago[deleted]
- bigmanwalter 3y agoRust is good for writing performant code, incorporates a lot of the latest programming language research, and gives great error messages. You don't need it. But if you prefer using it, it's nice to have a web development framework.
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]
- nonethewiser 3y agoI asked the same question and imagined a snarky response like "Well whenever you want a fast, memory-safe api." But seriously, I don't know. It seems like it trades development speed for things that just aren't problems. I think the database would be where most performance issues would surface, not the api server. I'm curious how others will answer your question though because I'm not really sure.
- hu3 3y agoEven when performance is important, C# and Java are top performers: https://www.techempower.com/benchmarks/#section=data-r21 https://www.techempower.com/benchmarks/#section=data-r21 Heck people use some incantations of Java for High Frequency Trading even. Besides, web application bottleneck is usually the database.
- riquito 3y agoWhat you write and what's in the results you linked tells quite a different story (composite scores)
- hu3 3y agoAre we looking at the same thing? https://i.imgur.com/blA0Oi4.png https://i.imgur.com/blA0Oi4.png
- riquito 3y agoPerhaps I misinterpreted what you said as "Even when performance is important, C# and Java are top performers". I read it as "they are the top performers", and there are faster rust frameworks in that benchmark, but perhaps you meant "Among the top performers there are non-rust language which are good options without having to use rust"
- hu3 3y agoInterestingly, the fastest in that benchmark, above Rust, C++, Java and C# is... JavaScript. Goes to show how benchmark minigames are broken and also that most languages are good enough.
- shpongled 3y agoThere is some trade-off in development speed, but I think it's outweighed by the productivity gains from a great static type system and language that is relatively free of footguns. I have built several APIs with Rust + Axum + Sqlx. I get statically typed SQL queries, rock-solid performance, easy to deploy. Most of these APIs also interface with AWS stuff at some point, and the Rust SDK is just phenomenal to use. But I also love Rust. I've been writing it for 6 years now, and I am more productive in Rust than any other language (for non-trivial projects). I can write up an API faster in Rust than in Django, because I don't have to spend time digging through configuration files or installing plugins and reading arcane documentation to do what I want. The above stack in Rust is incredibly simple.
- camdenreslink 3y agoGood performance, nice type system to model business logic, easy to deploy a single executable. Low resource usage can be more affordable at a certain scale. A lot of concurrency models that you can choose from. Other languages have some of those features, but not necessarily all.
- bobbylarrybobby 3y agoYou don't. But despite its reputation, rust is an incredibly pleasant language to work in and so if you're already using it, it would naturally be what you reach for for your next project.
- pyr0hu 3y agoNot web development per se, but I had to write an FFI connector in Rust (because of some multiarch shenanigans) and I want to create an API to manage the connector remotely - it's a proxy for card readers - so I can manage the gates, the config, etc. through a HTTP api as the rust proxy is at the moment is just a daemon.
- infamouscow 3y agoMost of the Rust folks aren't interested in articulated discussion about trade offs, they're zealots making a moral argument and view themselves with a sense of divine superiority parallel to the Christian crusades. This is made exceedingly clear if you ask for specific examples of when Rust shouldn't be your first choice or when Rust is second-fiddle to more optimal solutions.
- fleventynine 3y agoMost of us don't spend our time arguing online; we're busy using the language in domains where it's clearly the best choice: embedded and systems software where memory safety and a tight memory footprint are more important than productivity for new developers. Once you have a few years experience under your belt, it's natural to want to use the language in other domains like large web applications, even though it's only a reasonable choice because you already spent the effort to learn the language.
- bowsamic 3y ago> Most of us don't spend our time arguing online; we're busy using the language in domains where it's clearly the best choice That seems like a highly unrealistic claim to me.
- fleventynine 3y agoThe fact that there are some domains where Rust is clearly the best choice? Or that there are plenty of corporate Rust users who don't make their language choice part of their identity?
- bowsamic 3y agoThe latter
- gv83 3y agoyou forgot the part about parroting arguments around "soundness", "realiability", "correctness", "easier to reason about" and "refactorings" for the 2-internal-users-only 2 models crud, completely ignoring the notion of non-functional requirements. they already killed scala, let's see how much time they need to kill rust
- commandar 3y agoI could see potential value in the semi-embedded device space. 3D printers are an area where I've been kind of expecting Rust to eventually take hold. Printers require fairly performant systems level firmware but the trend is toward users interacting with them pretty much entirely via webui. Right now, Klipper is one of the more popular 3DP firmwares. It's a mishmash of Python and C at the firmware layer with Moonraker (Python) sitting at the API layer and then some soft of JS-based UI like Mainsail or Fluidd sitting on top. I can see very real appeal to squashing the firmware and API layers down into a more coherent stack. Having a batteries included web framework would be helpful there.
- devit 3y agoRust is the best programming language, so the question is more why you wouldn't use it. And the answer is you wouldn't use it if there's a library or existing codebase in another language that is much better than the Rust equivalent, and the program is short enough that it's simpler to directly use that language rather than writing a binding or RPC interface. Or if you need the software to be written by someone who doesn't know Rust and doesn't want to learn (but in that case, they might not be able to write a correct program in any language, so this strategy is probably best reserved when a program that only works properly sometimes is acceptable).
- Thaxll 3y agoComments like that make people not want to use Rust. As good as Rust is, there is no such thing as "best" language.
- adamnemecek 3y agoRust is as close to "best" as you can get.
- konart 3y agoThere is no such thing as "best" unless the problem and restrictions it creates are specified.
- synergy20 3y agowhat about golang for web developments then, it's arguably much easier to use, single binary, and memory safe.
- adamnemecek 3y agoEasier maybe, definitely not more pleasant, at least for me.
- jokethrowaway 3y agoI agree in principle, on the other side... I can't think of any other language with the combination of safety guarantees, high level language and a community producing very cool crates. Rust dethroned Haskell for me, and I'm excited my favourite language is actually an approachable one for once. I think everybody can learn Rust (unlike Haskell, I gave up on trying to teach people), you literally just follow the borrow checker until it works.
- freedomben 3y agoDisclaimer: I currently use Phoenix for everything web, and I've never written any serious rust although I want to because it intrigues me. I would imagine it's one of those "I already know Rust really well and I want to write a web app." Phoenix (like Rails back in the day) is one of those frameworks that makes it worth learning a new language, but those are the only two I know. The rest of the frameworks I've seen compelling are mostly to allow somebody to stay in the language/ecosystem that they're most confident/familiar with.
- indy 3y ago1. Efficient use of server hardware. I'm cheap and use a low-spec server 2. Code re-use between client and server. I have some application logic that can run on the server and on the client via WASM compilation
- masklinn 3y agoThe efficiency is also nice for paas/faas scenarios.
- dlisboa 3y agoOne reason would be reliability. Almost all of the errors on the application I work on are nil references or errors that were expected, but just weren't handled. Rust forces you to handle those at compile time, ending with a better all around software. There are other languages that achieve the same, I'm just comparing Rust to the usual suspects for web-dev (JavaScript, Ruby, Python, PHP, etc).
- gv83 3y agobetter for who? if you're building The Wrong Thing it doesn't matter. also, "soundness" and "reliability" are not non-functional requirements FOR EVERYTHING
- jokethrowaway 3y agoI choose Rust for web development, the oldest running product I have is ~2 years old at this point. Prototyping is slower but maintenance is faster. It's a trade-off. I have a bunch of products and every once and then something needs fixing. When it's one of my node.js or python projects it's usually a bath of blood and I'm never confident I changed the right things. With Rust I get a type error until everything is plugged in correctly - the only mistakes I get are logical ones. TypeScript kind of gives you a similar experience but it has more escape hatches. If you want to close all the exceptions and make everything type safe it will take you a similar amount of time as writing Rust code. The end result is that when I see a TS codebase I can't trust it: I might have written some unknown / any and there is a massive gap in types. This negates any benefits I get from type safety. In Rust this is not possible, as long as you're using safe dependencies (which you most likely are if you're writing a web service in Axum).
- DarkNova6 3y agoRust‘s Killer Feature is excellent support for Webassembly. No GC, no problem.