15 ms·
Is Rust web yet?
- notRobot 6y ago> Rust can even run on the browser, by compiling to WebAssembly . Forgive my ignorance (I haven't done front end web dev in almost a decade), but what is the use case for WebAssembly? What does it enable websites to do that (1) needs to be done within browsers and (2) can't be done with JS? Also, are there any prominent websites that use WebAssembly? It's shipped with all browsers, but what percentage of users ever make use of it?
- shrumm 6y agoFigma does, and they cut their load time down by 3x. As a frequent user, I can attest to how snappy it feels despite the heavy computations it needs to do in the background. Evan Wallace, their CTO did a great write up on it [1]. [1] https://www.figma.com/blog/webassembly-cut-figmas-load-time-by-3x/ https://www.figma.com/blog/webassembly-cut-figmas-load-time-...
- k__ 6y agoI find it strange when people say "cut by 3 times" What they did was cutting it to 30% or by 70%.
- nicoburns 6y agoIt depends if you think additively or multiplicatively: newLoadTime = oldLoadTime - (70% of oldLoadTime) newLoadTime = oldLoadTime / 3 Personally I find the additive expression unintuitive and find the multiplicative expression easier to reason about. "cut by" does generally indicate an additive expression. It should really have been phrased as something like "reduced by a factor of 3"
- cedex12 6y agohum, aren't both of your assignments the same (modulo 3.3%) ?
- nicoburns 6y agoYes, that's my point. You can phrase the same computation in both ways.
- k__ 6y agoBut it isn't a factor.
- nicoburns 6y agoIt is. Factor, noun "a number or quantity that when multiplied with another produces a given number or expression." It's not an exact integer factor, but I think the concept of factor is more general than that.
- deleted 6y ago[deleted]
- wongarsu 6y ago>It's not an exact integer factor That would imply the phrase has to be "reduced by a factor of 1/3", which leads to the wrong impression. The better technically correct phrase would be "reduced by a divisor of 3"
- the8472 6y agoIf you reduce it by a multiple > 1 of its total time it must be negative, i.e. it's giving you back CPU cycles every time you execute it. Quite impressive.
- eloisius 6y agoI’m also curious about how valuable writing rust that compiled to webasm is. Wouldn’t I still have to write a lot of un-rust-like code to manipulate the DOM? I could definitely see writing a core library in rust and wrapping it in a thin interface to use it in JS, though. Is that the idea?
- johncolanduoni 6y agoThe stand-out uses of WebAssembly have mostly been augmenting a JavaScript application that has strenuous computation needs in certain parts. As others have mentioned Figma, Twitch, etc. have used it to great effect without rewriting their entire app in Rust or another linear-memory based language.
- brohee 6y agohttps://tech.ebayinc.com/engineering/webassembly-at-ebay-a-real-world-use-case/ https://tech.ebayinc.com/engineering/webassembly-at-ebay-a-r...
- hknd 6y agohttps://webassembly.org/docs/use-cases/ https://webassembly.org/docs/use-cases/ TL;DR: - "almost fast as native code for web browsers” - in case you wanna do some expensive computing without a server - "Compiling Existing Applications for the Browser" - port existing code into the browser (eg cpp apps)
- arethuza 6y agoUsing webasm as a general purpose platform for the execution of untrusted code is also pretty interesting - this might be within server side code or non-browser desktop apps.
- m12k 6y agoIt's a way to do things in the browser that you normally can only do with JavaScript but with better performance and written in a different language
- tester34 6y agoYou can use existing e.g C# libraries on the client side (browser) e.g you can develop parser in console application and then ship it to the browser and use it there to parse e.g code without changing a single line of code or having to do some bullshit or traspiling it to js. Once it matures it will allow you to get rid of writing javascript and use java, c#, rust, c++ and many other to write frontend.
- secondcoming 6y agoBasically, multithreaded adverts.
- deleted 6y ago[deleted]
- sbelskie 6y agoThe main thing it can do that can’t be done with JS is not having to use JS. More seriously, one of the main draws is being able to us the same language on both the front and back end, which might be beneficial to reduce the need to duplicate model or just to be able to develop on the front end in ones preferred language.
- kevingadd 6y agoAmong other things, wasm has access to float32, int64 and vector types that JS does not. It also has operations like reinterpret_cast that you can't do in JS without a store/load pair using a scratch buffer.
- aikah 6y agoJS does have BigInts though https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- maleldil 6y agoParent referred to int64. BigInt and int64 are not the same thing. JS doesn't have integers; all numbers are represented as doubles. One of the reasons having actual integers is important is performance, as integer operations are often faster than floating point operations. BigInt doesn't help with that.
- ben-schaaf 6y agoMy use case is having written a compiler/interpreter in rust wasm lets you easily set up a playground for the language.
- kthxb 6y agoIt's purpose is not to replace JS, but to extend it. For example for the performamce critical parts of applications. It is already used in big JS libraries (such as Hyphenopoly, Google's Draco or Long.js) and in lots of custom applications like the Twitch.tv media player and many 3D visualizations.
- threeseed 6y agoOne example is source maps. I have a web app where every time there is an error on the client side it sends it back to the server. On normal JS it locks up the browser for 10+ seconds. In WASM it's instant. Never found another use except for this.
- tester34 6y ago>On normal JS it locks up the browser for 10+ seconds Weird, I think I do the same thing (global exception catcher) and it works fine
- Closi 6y ago> what is the use case for WebAssembly? I think the core use case is "Being something that's not Javascript". The desktop programming world gets benefit from having multiple languages that suit different use-cases, so why would the web not?
- pansa2 6y ago> what is the use case for WebAssembly? Personally, it allows me to write tools that can run either on the command line or in the browser. Only the user-interface need be rewritten - internally both versions can share a lot of code. WebAssembly makes it possible to do this using a language other than JavaScript. However, the languages I can use are still limited - AFAIK WebAssembly is currently only well-supported by C, C++ and Rust.
- sradman 6y ago> what is the use case for WebAssembly? There is no access to the DOM and the POSIX-like WASI interface is limited so the main use case is reusing code with manual memory management (C, Rust, etc). WebAssembly also targets server-side JavaScript runtimes like Node, Deno, and Cloudflare Workers.
- k__ 6y agoI saw that performance became more uniform with Rust/WASM. Not faster all over, but less slow in the worst cases.
- jlg23 6y agoAt the very minimum you can reuse the code for input validation on the server side in the client. Given that those, if maintained separately, tend to diverge, in my experience, this is a net win.
- akudha 6y agoSame questions, plus one more. Can anyone share a good resource that they have used to learn WebAssembly?
- arrayjumper 6y agoI used wasm for a computer vision related feature we built at work. It allowed us to reuse a bunch of things from opencv without having to reimplement those things in JS.
- zelly 6y agoWhere's the Rust Django? Is this false advertising?
- darthrupert 6y agoRocket still requires nightly. Rust folks should stop normalizing the use of nightly. Rust was "stabilized" almost 9 (edit 5,5 actually) years ago!
- jeltz 6y agoDo you have any idea why that is? I am pretty sure procedural macros in an expression context landed in stable 1 or 2 releases ago.
- mathstuf 6y agoI believe they are waiting for releases of dependencies to not declare feature requirements. There's an issue linked in this subthread already for tracking it.
- steveklabnik 6y agoThat is already done, and master builds on stable. They haven't cut a release yet because there's more they want in the release than just "whatever is on HEAD when we compile on stable."
- nicoburns 6y agoRocket's development process is quite slow, and they haven't but out a release since then.
- bschwindHN 6y agoWasn't Rust "stabilized" with its 1.0 release in 2015?
- Ygg2 6y agoYes. But meta programming facilities aren't stabilized for obvious reasons (it ossifies the current implementation).
- 6y ago
- rethab 6y agoAs someone who has written quite a few lines in rust (rocket, specifically, while working on https://digester.app https://digester.app) I will agree that rust "is web", and yes, you can replace your Django. But the development is experience and ecosystem is nowhere near (again, only speaking for rocket and I know a lot of work is being done to improve things) what you are used to from Django. For example, rocket's configuration system is quite limited (currently being reworked), poor cors support, limited test support, etc.. Again, not saying you can't do it, but it's not the same.
- jamil7 6y agoYeah it's a little disingenuous I think, there is basically nothing that matches the productiveness of Rails/Django when it comes to building webapps and without a clear reason why or strong community around it I'm not sure what the point would be. If you're building a CRUD app I don't think language performance is going to be the bottleneck. I think Rust looks awesome but as someone who uses multiple programming languages daily I feel like we're too often looking for one language that can do everything rather than just picking up the one that fits the problem area.
- dmos62 6y ago> there is basically nothing that matches the productiveness of Rails/Django when it comes to building webapps That's a strong statement. Anyone care to back it up? I've never used Rails/Django.
- jeltz 6y agoI have used Rails professionally and I disagree with it. Personally I think Roda and Sinatra are more productive than Rails for most applications. Where Rails shines is the big plugin ecosystem, but many of those plugins are sadly not the great. And ignoring the plugin ecosystem Rails is pretty meh, not any worse or better than any of hundreds of frameworks out there. I would certainly not count it among the best ones.
- fernandotakai 6y ago
- txdv 6y agoI love the fact that they have their own native implementations of clients for mysql, postgres and mongo. In the Java world people just use jdbc and wrap it with a threadpool and expose it as "async", but in rust it is truly async down to the system call.
- _cobe_bero__ 6y agoThere are several async drivers for Java, the most prominent probably https://vertx.io/docs/#data_access https://vertx.io/docs/#data_access. Go, Python, C# have native implementations as well, e.g. the de facto standard Postgres driver for Go (which is by the way super fast), https://github.com/JackC/pgx https://github.com/JackC/pgx
- jbverschoor 6y agoOrm, controllers, templates and routing is not nearly as complete as the rails stack and ecosystem. Same goes for Phoenix
- Droobfest 6y agoDo you mean that Rust is not as complete as Phoenix, or that Phoenix is not as complete as Rails?
- galfarragem 6y agoIs Rust marketable yet? Stackoverflow jobs (2020-10-30) that require: Rust - 15/2462 C - 71/2462 Go - 105/2462 Kotlin - 109/2462 Typescript - 147/2462 C++ - 193/2462 C# - 221/2462 Java - 544/2462
- walkingolof 6y agoThe only rust jobs I’ve seen so far are “crypto/blockchain”, but I’m just casually follow the development, anyone knows other niches adopting Rust?
- iExploder 6y agoembedded / iot / automotive, this currently stands on c ecosystem due to suppliers and billions of lines of legacy code the failure of rust was it tried to start from scratch where better solution would be to seamlessly integrate into c, maybe if gcc has support for compiling rust the future switchover on embedded would be easier
- deleted 6y ago[deleted]
- _cobe_bero__ 6y agoI've done some researching for Rust jobs in several European countries. It's basically everywhere well below 1% of all dev job offers.
- simias 6y agoIt'll probably take a few more years still. I've started introducing rust into my "stack" at work for some new projects and I'm sure I'm not the only one in this situation, so when I decide to move to a different job there'll probably be one more Rust opening for somebody to take over. The ecosystem needs to settle and stabilize a bit more before it reaches deep adoption in the industry as a whole. If you're a lean "disruptive" start up then you probably don't mind using more experimental technologies but big, established companies like to have a more long term vision. You don't want to have to rewrite half of your software 5 years from now because nobody uses FancyLang anymore.
- hugodutka 6y agoI have been dabbling in Rust web development lately, coming from a Django/Flask background. I take issue with the article stating: > Can I replace my Rails/Django/Flask already? Yup! While I agree that you can try to replace Flask with Rust web frameworks, you can't do it for Rails or Django. Rust web frameworks do not let you easily test your application's database access layer nor provide advanced authorization, and lack other features that become necessary when your application becomes bigger. If you don't need the performance that Rust provides, you should still go for Django or Rails. Otherwise you will end up reinventing them.
- akmittal 6y agoEven if performance matter Go should be a better choice. Go's performance is very close to rust in Web ecosystem and is very mature.
- legulere 6y agoOr C# with ASP.NET Core which is much closer to rust in performance.
- jeswin 6y ago> Or C# with ASP.NET Core which is much closer to rust in performance. I haven't noticed that C# is faster than Go, or that it's as fast as Rust/C++. Except in selected micro-benchmarks, of course. C# is at best in the same bracket as Go: https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=query https://www.techempower.com/benchmarks/#section=data-r19&hw=...
- xiaodai 6y agoWouldn't rust fail for the same reason there is no c++ framework that cna take on django? Rust is a pretty complex framework.
- daniel_iversen 6y agoBut is it web scale? ;)
- cyberfart 6y agoIt has joins, so no ;)
- waynesonfire 6y agoTitle needs to be updated.
- _cobe_bero__ 6y agoRust has been "web ready" for some time. C++ is "web ready", too. But why should one choose Rust when there're plenty of alternatives with much larger and much more stable ecosystems. And those alternatives offer much higher productivity and a much larger talent pool. Rust is not even the fastest web framework (https://www.techempower.com/benchmarks/ https://www.techempower.com/benchmarks/) . And the benefit over Java, C# or Go is really negligible. Who needs more than 300000 req/s and can't afford servers to scale? So, another nice try from the Rust evangelists, but no thanks.
- infinityplus1 6y agoMany people use Node.js and Javascript because they get to use one language on both server and web browser. Rust can probably do the same in future. Rust on server, Rust with WASM on web browsers and then Rust for local software.
- tupputuppu 6y agoRight, so you're saying we can take rust web backend seriously once Rust is popular in front ends? Cool, I agree, but that's just never going to happen.
- zcw100 6y agoWhy should we do anything new? I've been seeing this attitude more and more where developers think they're entitled to be convinced to use some new technology as though their time and attention are so valuable it's someone else's responsibility to convince them to spend it. What I think differentiates this from normal outreach and education that every project needs to do to build a community is the sense of entitlement and the declaration that they're outright hostile and argumentative and then expect to be engaged.
- amelius 6y ago> Why should we do anything new? I think a problem exists when that something new is being pushed and hyped in order to create a self-fulfilling prophecy where everybody starts jumping on the bandwagon and an ecosystem is built.
- mkl95 6y agoCan you trivially write a CRUD service with Swagger docs and JWT authentication using Rust? And how does performance compare to a FastAPI app?
- steveklabnik 6y agoMy company is writing services that use OpenAPI (aka Swagger) heavily. I don't believe we are doing JWT currently. https://github.com/oxidecomputer/dropshot https://github.com/oxidecomputer/dropshot I've never used FastAPI, but https://www.techempower.com/benchmarks/#section=data-r19 https://www.techempower.com/benchmarks/#section=data-r19 (which is the first thing TechEmpower shows me) says that for this specific test (and maybe others are different, you should look into it!), FastAPI does 52,080 RPS, and actix-core does 651,144.
- Dowwie 6y agoOne person's trivial 1-day of effort is another person's month. There's a solid jsonwebtoken library that could be used in a custom token authentication middleware, if the one in the ecosystem is unsatisfactory. It's not trivial to learn a web framework and how to write custom middleware, but if you know where to look for actix-web there is an example: https://github.com/actix/actix-extras/blob/master/actix-web-httpauth/examples/middleware.rs https://github.com/actix/actix-extras/blob/master/actix-web-...
- qaq 6y agoWhen Rocket lands Async/Await and other major reworks in flight maybe. Actix-Web is fast but ergonomics of writing Actix web apps are def. substandard compared to other mature ecosystems.
- _huayra_ 6y agoIs there a web framework / ecosystem built on a statically-typed, non-JVM language that comes close to the feature set of either Django/Rails? After spending too much time chasing down dynamic-typing related bugs in both of those frameworks, I find myself missing a lot of their feature set when I look at other frameworks. However, I'm tired of doing "defensive programming" in Python to essentially statically assert argument types and unit test things that a statically-typed language would disallow by construction. This stuff in Rust, Go, and even Nim [0] look interesting, but the consensus seems to be the value proposition of Rails or Django is still hard to beat unfortunately. [0] https://nim-lang.org/ https://nim-lang.org/
- asplake 6y agoCan I add "ML-typed" to your spec? That's what would finally make me jump from Python/Flask
- izzle49 6y agojust curious why non jvm?
- _huayra_ 6y agoI haven't used the JVM in a long time, but judging by the web framework benchmarks I've checked out this morning e.g. [0], it seems like there are many Go frameworks that beat those on the JVM. I agree with other commenters on this thread that in general such benchmarks may not mean a lot when compute is so cheap and the autoscaling infrastructure is awesome, but I often work on embedded platforms or other resource constrained devices where adding the JVM is a nonstarter (not that Django or Rails is an option either in those cases). [0] https://github.com/the-benchmarker/web-frameworks https://github.com/the-benchmarker/web-frameworks
- flohofwoe 6y agoI'm a big fan of WASM to run my cross-platform code in browsers, but everytime I see it pitched as wholesale replacement for Javascript frameworks which sit on top of the DOM I flinch a bit. This is essentially the reverse of "with Electron you can now create native applications entirely in Javascript". Yes it works, but only with a lot of overhead that wouldn't exist by doing it the "straightforward" way. A much smarter approach is to create hybrid JS/WASM applications, manage the UI in Javascript, move isolated standalone features (cross-platform code or performance-sensitive code) into WASM modules, and call into those WASM modules from JS.
- jabl 6y agoWill we see the next generation of electron applications using WASM for the bulk, and JS for the UI?
- untog 6y agoI’d be surprised, given that one of the big arguments for using Electron is that you get to write it in JS. If you write Rust for WASM you could just use a native UI framework and target that instead!
- flohofwoe 6y agoIMHO the USP of Electron isn't even that you can write the logic in Javascript, but that it's the option that "sucks least" for creating cross-platform UI applications.
- flohofwoe 6y agoHeh, good point. In my last sentence I was thinking about web apps running in browsers, not about Electron (but of course there's a lot of overlap). For native applications, maybe a better idea is to drive the UI with native code, and use WASM to run "untrusted" external code (for instance extensions/plugins), because a WASM runtime is a lot smaller than a complete browser engine like Electron.
- hackerfromthefu 6y ago
- chickahoona 6y agoSo in summary I'd say that HN highly disagrees with the author...
- ablekh 6y agoSpeaking of Rust's WebAssembly runtime option, I would argue that, unless one is heavily biased toward using Rust, ASP.NET's Blazor WebAssembly host option has a more attractive value proposition overall, due to a much more comprehensive developer and tooling ecosystems. I'm quite impressed by Microsoft's Blazor and .NET Core teams working on improving Blazor's performance and decreasing the system bundle's download size. Blazor's performance in upcoming .NET 5 is reported to be already 2-3x better than in .NET 3. I expect that ongoing work on ahead-of-time (AOT) compilation to WebAssembly, including an ability to freely mix AOT- and JIT-compiled code (expected to be shipped as part of .NET 6) will further improve Blazor's competitive position vs. Rust's WebAssembly from the performance perspective.
- legulere 6y agoThe problem with blazor is that the only thing that is in webassembly is the bytecode interpreter and not your code. More is currently problematic because too much C# code relies on reflection making AOT difficult and webassembly not having garbage collection integration yet.
- hackerfromthefu 6y agoThat is not correct, or not the full story. Blazor has two separate modes, 'Server Side' and 'Web Assembly'. What you're describing is the server side mode. The second mode, called Web Assembly, compiles your code to WASM that is executed in the browser. https://docs.microsoft.com/en-us/aspnet/core/blazor/hosting-models?view=aspnetcore-3.1 https://docs.microsoft.com/en-us/aspnet/core/blazor/hosting-... Also, "The .NET 5.0 core framework libraries have been annotated to indicate what works in the WebAssembly runtime, so developers now get a warning in the code editor when attempting to call an unsupported method." from https://www.theregister.com/2020/10/15/microsoft_emits_net_50_go/ https://www.theregister.com/2020/10/15/microsoft_emits_net_5...
- legulere 6y agoNope the server version has no Webassembly at all. The Webassembly version lets a .NET IL interpreter in WA running your code.
- maallooc 6y agoOh yeah, real mature. Have fun!
- lipanski 6y agoI spent some of my time building or trying to build various web apps in both Rust and Crystal. The Rust web experience of several years ago was very frustrating and it was partially due to the lacking ecosystem but also due to the nature of the language. The safety guarantees that the language provides are great if you care about that, but they can be quite a pain when you just want to get something out. The majority of web projects fall in the last category. The language ergonomics have improved since (you don't have to do so much pointer juggling any more) but it's still no way near other languages that might only cover these guarantees partially or not at all. Language ergonomics is a very important aspect because it can limit both the development speed of your project but also the speed at which the ecosystem develops. The performance aspect (aside from WebAssembly, where it has few contenders) is something that can be partially matched by other technologies. By comparsion, developing for the web in Crystal is quite enjoyable. The language has great ergonomics (I'd say even better than Ruby). The web ecosystem might not be mature but it's blooming and it has you covered in the main areas. Most importantly, if you're missing something, it's very easy to build it yourself. The standard library contains a lot of web goodies, including a very decent HTTP client, a server, easy to use and fast JSON and XML parsers, an OAuth2 client (yes!). The language feels like it was built for the web, which I can't say about Rust. In the end, what matters is your use case and the trade-offs you are willing to make (development speed vs. performance vs. safety guarantees). If I would have to build a load balancer, I might consider Rust. For a normal web app, I'd personally go with something like Crystal, Ruby, Python, Node.
- jkoudys 6y agoMy company Clausehound has completely moved its legal tech contract analysis and version control platform onto rust, and launched a couple months ago. It's been fantastic. We're a similar setup to a lot of the top links on there (actix-web over juniper for graphql resolving with sqlx). While the speed is incredible, the biggest improvement has been the types system. I've never had such an easy experience being able to pick and choose libraries based on shared traits - eg we could authorize on jwt using jsonwebtoken, load fairly complex migrated relational data into our nice models, and even wrote the crate phpass so we could keep some accounts created back when we were a WordPress blog working. The strict typing in graphql has made dataloaders orders of magnitude faster. The same code that makes our business logic clear makes it easy to figure out if graphql needs to resolve all those nodes with individual sql queries, one against the parent node, build some `IN (?,?,?,?)` prepared statement, or resolve from cache. String manipulation is definitely a bit harder, but otherwise the experience as a web app developer has been amazing.
- andrewnc 6y agoWould you agree that the resources in the linked article are a good starting point to learn about your specific rust stack, or do you have additional resources you would recommend?
- jkoudys 6y agoYeah, I probably have been a lazy member of the greater dev community because I learned a lot of these things but never blogged about it myself. Juniper for graphql is a big missing piece from that page -- gql is big enough as an alternative to REST that it ought to be at least considered, while RESTful services typically come baked-in because they rely so much on standard HTTP (so their use with eg actix-web is obvious). What I really found amazing was how we could write one struct, e.g. an Organization, and easily build them from JWT claims, SQL queries, graphql payloads, or POST params. With many other framework libraries, I'd really agonize over graphql vs rest, but because the types are so rigidly defined, it's very easy to write the definitions once and use them everywhere, so RESTful endpoints are simple to setup where there's a client demand for them. An extremely cool new one is serde_pickle support (python's favourite binary serialization), which we're using to load tiny word-vectorization dictionaries in WASM. This lets lawyers collaborate concurrently on the same contract, and farms out the laptops/phones they're working on's GPU cycles to auto-draft the contract (e.g. type 8 words, and can see "85% chance this a non-disparagement clause -- here's some example language you can use. Here's some case law saying when it's enforceable and when it's not").
- a012 6y agoI'm new to Rust and trying to do some tasks with Rust's rusoto library, but it seems like too verbose and lacking documents as well as examples of how one can do things with it. Comparing to boto3 library, it's a steep learning curve to me.
- speedgoose 6y agoI am playing with Rust on a side project. I use graphql with juniper on the server side, and WebAssembly on the client side, together with Vue. I love it. It's still more complex and verbose than a full javascript project, and the compilation time are long but I enjoy it. I would recommend Rust over Typescript, if you are going to spend time on types, use Rust it's more worth it.
- k__ 6y agoAny resources on how to get started? I tought about using Rust instead of JavaScript for frontend for some time. On the one hand, Rust is a step back, because there is quite some things you have to do more than with JavaScript. On the other hand, Rust has an interesting type system that could save you in the long run and things like pattern-matching and expressions everywhere is even a direct usability improvement over JavaScript. So it's not, Rust is more low-level than JavaScript, that's why it's bad for frontend, but more, Rust is different from JavaScript some parts are harder, some are easier.
- speedgoose 6y agoI went with the official documentation of rust and rust-wasm. It was okay. I would recommend to use the best tool for your problem. If you want to display a button and manage click events, don't use Rust it's not worth it.
- tupputuppu 6y agoWorth it in which way? Due to the types? So the vast ecosystem and ready functionality offered by typescript or other high level languages is worth less than what exactly?
- speedgoose 6y agoDealing with types is boring so if I'm going to spend time on this, it should have enough benefits. In my humble opinion the rust typing system is more interesting than what typescript can offer. The main advantage for me is the monad. Sure you could use monads in typescript or even vanilla javascript but in Rust, everything uses monads. The vast javascript ecosystem is available to rust in the browser too. Server side it's not as big and I agree javascript has a point there. But now, if you look at the ecosystem of libraries with proper and up-to-date typescript definitions, well it's not that great.
- kissgyorgy 6y agoSaying that it can replace Django is quite an overstatement! The only framework which can be compared in features is Rails and Spring, nothing else even comes close! Not to mention the productivity benefits... Rust is a good language, but with these compile times for a complex Django-like web application? No thanks.
- wil421 6y agoNot to mention Django (and flask) come with a ton of modules to get you up and running. Not sure I personally feel comfortable building my own authentication modules. The rocket example was similar to one I did in flask but with flask I didn’t feel like I was creating my own auth. Rocket guards and JWT left me feeling like it was much easier to make a huge mistake.
- Benjmhart 6y agoYeah, but those compile times catch bugs everyone misses in your Django app. People think speed is the only advantage, reducing runtime debugging and providing a more secure, more correct front end, free null pointer issues and free of memory leaks and runtime type errors - rust just has the added bonus of being fast. You're right some of the tools aren't quite there and if you move a rails-y app over to rust, you have a job ahead of you to assemble some libraries, but it is doable - the point is that you can put rust in production at web scale now.
- Dowwie 6y agoIt is absolutely an overstatement and people should be more careful with misrepresenting what the Rust language and ecosystem offers. Rust has its strengths just as Python does. None of the authors of the web frameworks are aspiring to build a Django or Flask like experience.
- gremlinsinc 6y agoWhat about laravel? Rails doesn't even have it's own authentication built in? Seems laravel, might be closer to django, and with jetstream - it has an admin area baked in, which others don't. Laravel is also just as, if not more performant (if you mix in swoole).
- thrownaway954 6y agolove how it claims that "it's freaking fast", yet has no performance metrics on the page. granted they might be hidden behind a link a or two, but i'm going hunting for something when you should have it right there on the page to back up your claims.
- The_rationalist 6y agoLet's remember that while actix web rank very high in techempower up, most of it's performance lead come because of it's async connection with postgres. Other languages will catch up in this regards in a few years (e.g loom for Spring)
- 40four 6y agoI’m sure I’m not the only one wondering, but why would someone want to write web code in Rust. To be fair, as a web developer by day, I still haven’t gotten around to trying to write any Rust in my free time. I am curious though. But after browsing the docs of actix-web and rocket, it seems a bit of a reach to say you could use these solutions in place of monolithic frameworks Django or Rails. Maybe if they had said they could take the place of an Express/ Slim / Flask app I wouldn’t have rolled my eyes as hard. Wouldn’t these battle tested ‘micro’ frameworks be a better comparison? Anyway, since I really know next to nothing about Rust, what would be the benefits for me to pick say, Actix-web over Slim to start a new project? I get the feeling the best reason would be I’m already an experienced Rust developer and want to leverage that domain knowledge. Or maybe a team that already writes a lot of Rust wants to keep consistency over their repos.
- couchand 6y agoThe best part about Rust is the type system. For one example, in a web app I'm building for a client, we have two types to represent invoice ids: one for the invoice id that came back in a response from the API, and one for an invoice id that a user is asking for. They are distinct because we know that an InvoiceId refers to an actual invoice in the system, and a UnverifiedInvoiceId might not. Both of them are distinct from a CustomerId or any other id. This might sound like it could get cumbersome fast, but it's actually really simple in practice, due to clever uses of traits. UnverifiedInvoiceId implements rocket::FromParam, so I can deserialize it from a URL parameter. InvoiceId is only created in the serde::Deserialize implementation of an invoice-returning API response. So a (significantly simplified) endpoint in the app might look like: #[get("/invoices/<unverified_invoice_id>")] pub fn get_invoice_by_id( unverified_invoice_id: UnverifiedInvoiceId, api_conn: ApiConnection, ) -> HtmlResponse { // API "search" methods take unverified user input as parameters let invoice = api_conn.fetch_invoice_by_id(unverified_invoice_id); // API "lookup" methods take verified ids let line_items = api_conn.fetch_invoice_line_items(invoice.id); render_invoice(invoice, line_items); } I can't accidentally switch up things that don't belong together, even though under the hood they're all just unsigned ints.
- 6y ago
- ronanyeah 6y agoI come from a Node.js background and picked up Rust about a year ago, after dabbling with Haskell, Elixir and Purescript. --- Things I like: - Modern type system. Sum types, Option type etc - Strict compiler. If it compiles, it works. - Great error messages. - Mature package tooling. Cargo is at least as good as npm. - Mature GraphQL packages. - Decent cloud support. Github actions, Container guides. --- I've been running it in production for a while, usually as a remote schema for Hasura: https://github.com/ronanyeah/rust-hasura https://github.com/ronanyeah/rust-hasura Deploy pipeline: - Push to github - Github action builds binary - Github action pushes binary to AWS ECS in a container - This triggers a rebuild of the AWS Fargate service which restarts with new Rust code
- pjmlp 6y agoOnly for certain kinds of workloads, definitely not for what I do with JavaEE/JakartaEE/LifeRay, ASP.NET (SharePOint, Sitecore) projects, alongside RDMS like DB2, SQL Server and Oracle.
- ufmace 6y agoHas anybody else actually clicked through some of the links to the topics that are supposedly ready? Authentication/Authorization - for me, this means something like Rails Devise, which gets you a full set of routes, controllers, and views for user management, including correct session management, account creation, password reset, all using best-practices for handling passwords, session tokens, and reset workflows. Instead, we get a few cookie and JWT widgets. Nowhere near ready. CMS - they list 3 static site generators. A static site generator is all well and good, but it's nowhere near being a CMS. They not only don't have a CMS, but don't even seem to know what a CMS is or that they need one and that a static site generator is not a substitute. Database - it at least does have some okay ORMs. But do any web frameworks integrate with them to the extent that you can set up test databases and run test suites with them automatically? Do any of them support validations? Last I checked, Diesel's support for associations is pretty bare-bones. I've tried out Rocket. It's all right for making relatively basic API apps. And it still doesn't build on Stable yet, though that's hopefully coming soon. I like Rust for a lot of things, but it has a long way to go before it can compete with full-fledged web frameworks.
- gremlinsinc 6y agoHave you tried laravel? One thing I hate about rails is devise. laravel new app --jetstream gets me an app with admin area, profile page, teams, my choice of livewire (like phoenix liveview), or vue + inertiajs (spa w/out vue-router i.e. using laravel's native router), I also get 2 factor built into the auth layer. Might be 8 hours of work just to get rails to have all that laravel brings from the scaffold command for a new project.
- gwbas1c 6y ago> Is Rust web yet? Only if you REALLY need it, like if you're embedding a web server into an existing Rust service. Otherwise, it's going to be very time consuming to do things that are straightforward in other languages. (TLDR: A Rust++, or "Objective Rust" that simplifies some memory issues could make Rust web ready.) For the past few months, my occasional hobby has been trying to learn Rust. BUT, I've also spent a considerable amount of time getting up to speed in NodeJS. Regarding running Rust in the browser with WebAssembly: I've spent DAYS trying to figure out how to hook callbacks into the DOM cleanly. I basically went through the "Game of Life" walkthough, (https://rustwasm.github.io/docs/book/ https://rustwasm.github.io/docs/book/), and then ported all of the JavaScript sides into Rust. Trying to make registering a callback from the DOM as clean as implementing a button click handler in C# is just a nightmare. The problem is that Rust just isn't good for complicated object graphs. This is where almost any language that's garbage collected, or uses some form of automatic reference counting, shines. And, if you're building a "normal" web application, Rust isn't going to have tangible performance advantage over Java / C# / NodeJS / Python. (Meaning, if you aren't running at Google Scale, there's no tangible performance advantage for Rust.) Part of what happens in Rust is that it's very hard for a struct to reference itself so it can register event callbacks. You're forced to either make all users of the struct use reference counting, or you have to encapsulate a reference counted type used with callbacks. In a garbage collected language, this kind of hurdle isn't needed. In reference counted languages, registering event handlers just requires a weak reference to yourself to avoid cyclic loops. This is because GC / ARC languages assume the same memory model for all objects; which isn't the case in Rust. Anyway, to make Rust easier to work with, it needs a way to trade some of the raw, "0-cost-abstraction" advantages for the advantages that come with GC / ARC languages. Need raw performance? Use pure Rust. Just need to get it done? Use a higher-level syntax.
- Dowwie 6y agoPeople are making a mistake of evaluating Rust web development exclusively on the basis of performance. If you're doing web development professionally, using Rust will make you more productive and happy. The first few months onboarding with the language are challenging, but working with Rust is a very rewarding experience. The thing about Rust web dev expertise is that once you reach parity in capabilities with that of another language, there's no reason not to use Rust even where performance isn't absolutely necessary. There's no going back once you've gone down the Rust path because you'll be able to build better solutions with even greater velocity than if you were doing so with a dynamic language. Again, the first few months working with Rust are challenging, but it pays off!
- gremlinsinc 6y agoSo, is there a way for me to use an easy cli command like: laravel new myapp --jetstream And have SaaS style teams, admin area, authentication, 2-factor, tailwind layouts, and vue+inertia all configured for me, so I literally just need to build the unique feature parts and not worry about auth/sessions/etc?
- Dowwie 6y agoThe open source ecosystem isn't there yet. Actix web and rocket are best positioned to get there soonest. There comes a point where people invest effort into convenience projects such as command line boilerplate generation, but I don't think anyone using Rust right now has this as a priority. Rust crates and modules design make re-use and importing functionality straightforward and explicit. I am not aware of an admin area, but that may very well be what people contribute next. Actix web has the most robust ecosystem at the moment. You'll struggle less than I did because of it (I was an early adopter).
- nivethan 6y agoI wrote a tutorial on making a web app and I have some thoughts in general about rust in the final chapter. https://dev.to/krowemoh/a-web-app-in-rust-17-conclusion-1njd https://dev.to/krowemoh/a-web-app-in-rust-17-conclusion-1njd For the most part you could replace most things with rust but you'll be rolling your own solutions for things that other frameworks already supply. Actix was great to use and has enough middleware that I feel comfortable using it. I don't see any reason outside of desire though to use rust and actix, python and flask are basically the same thing but easier to write. Luckily I like the language and it is fun so for now I'll continue using it. It could be rust will be better once you have business logic where the borrow checker could really shine, just making a simple crud is too much glue work such that any programming language would work.
- mwcampbell 6y agoWe all know Rust web frameworks can't go head to head with Rails or Django; in other words, they're probably not the best fit for typical CRUD applications. But what I wonder is if there's yet a Rust web framework or set of libraries that would be a good fit for the type of stateful real-time web application where Phoenix is such a good fit right now. That is, a framework based on something like the actor model, with fault tolerance and clustering, with WebSocket-based channels built atop those actors, and possibly topped off with a real-time thin-client system like Phoenix LiveView. Those things, plus a statically-typed AOT-compiled language with great runtime efficiency like Rust, would be a killer combination.
- georgesC 6y agoI don't understand how people are jumping head first into a new technology that is so young. It reminds me of the different js frameworks fads. Why would you use that in production, with no decent level of certainties about the status of the project long term? Web is high level scripting, and lower level languages can be used by those high level languages to provide the required speed. The performance of those languages do increase over time with new hardware and discoveries. You can hardly do better than the concise syntax of php or python, depending on your preferences, in terms of performance vs code length. To me programming has always been about obeying the KISS principle. Does using rust for the web corresponds to that principle? I'm unconvinced. Compare rust code to php code. php might be slower to process big operations, but big operations shouldn't be left to php anyway. php is a high level scripting language. Contribute to php and writing an extension would be a better way to go in my opinion. This or another scripting language.
- phizy 6y agoWould you rather have an expert in Rust doing web programming in Rust, or a novice in JS doing web programming in JS? The best language to use is the one you know how to use best. If you know all languages equally well that you're free to choose the ideal language for every project, then sure, that's the way to go.
- georgesC 6y agoFor web dev, I would rather have an expert in rust obviously, but I would also rather have an expert in php who expressly choose php over rust for the sake of the kiss principle. Plus he would probably be satisfied with a lower starting salary :-) But you are right, reality often goes differently than what's thought to be ideal, which is why "perfect" solutions sometimes doesn't gets adopted in favor of a less perfect solution, which leaves the old "perfect" solution forgotten by history.