4 ms·
I hate JS but replacing it with Rust for front end is a bad idea, Rust is a low level systems programming language, it's very suboptimal for high level front en
by rubber_duck 10y ago
I hate JS but replacing it with Rust for front end is a bad idea, Rust is a low level systems programming language, it's very suboptimal for high level front end code from productivity standpoint and it adds no value because it's advantages (mem safety with 0 cost abstractions) don't really matter in frontend (JS is super bad at being optimizable but it's still more than sufficiently fast).
- Manishearth 10y agomemory safety isn't the only advantage. 0 cost abstractions do matter a bit. In general abstractions let you do high level programming in lower level languages. The type system matters a lot. I used to do a lot of scripting. One thing I really missed was having a good static type system. These days I miss ADT enums in all languages. Scripting is already moving in the direction of being more type safe (typescript, python type annotations), which is awesome, but I'd love to use something like Rust in that sphere.
- adwhit 10y agoRust is indeed known for memory safety and zero cost abstractions. But there is another side to Rust which is even more interesting - a type system that is almost as powerful as those of functional languages like OCaml and Haskell, but wrapped in approachable imperative syntax. With such a type system, it is possible to encode the invariants of your application in types (using generics and algebraic data types). Then you can get very close to "if it compiles, it works". JS, in particular, is the opposite. I am never really convinced that any JS I have written is "correct". It works, until one day it doesn't. This is such a problem that there have been multiple attempts to retrofit type-systems on top of it. Rust needn't be the only language that brings strong typing to the frontend (Elm has been around for years now). But I think the prospect of speed and correctness both front and back is pretty exciting.
- rubber_duck 10y ago>But there is another side to Rust which is even more interesting - a type system that is almost as powerful as those of functional languages like OCaml and Haskell, but wrapped in approachable imperative syntax. That type system is pretty verbose because it's aimed at manual memory management which you don't really care about in front end, and the compile times are huge compared to say TypeScript or something along those lines so yeah - I agree static typing is nice - but saying you should use Rust for front-end because it has static typing is like saying every gardener should have an excavator because digging holes with hands sucks - shovels exist.
- adwhit 10y agoI don't necessarily disagree with you, but when wasm is fully established I expect to see (another) step change in the complexity of the web. Fully-featured applications, 3D, VR, AR etc. We are on the brink of it already. And beyond a certain complexity (a relatively small amount of complexity, I would argue), a decent type system is essential. Rust just happens to be well positioned to take advantage of all this.
- static_noise 10y agoAre you saying because it can do A it can't do B? Are A and B mutually exclusive per se or is that just an unfounded assumption?
- rubber_duck 10y agoIt's a design trade off. I don't get why people are so pissy about it - Rust makes design choices that are suited for low level systems programming language - but it has a lot of noise and complicated things from high level language stand point, and compile times + debugging + lack of run time tweak-ability make it very unproductive for front end compared to say TS/JS
- EugeneOZ 10y agoI use Rust for web 1 year already and I can say it's awesome. Try.
- kibwen 10y agoBut on the backend, not on the client, I presume? If you've really been deploying Rust over the wire via asm.js, then some commendations are in order for your persistence. :P
- EugeneOZ 10y agoYes, of course. But in parallel I write code in TypeScript (frontend) and after few months performance is equivalent in both languages. Only difference - no runtime errors in Rust.
- rubber_duck 10y agoAre you joking ? You can have hot module replacement in TypeScript meaning you don't even have to refresh the page to get new code in browser - and then you can fire up the REPL and prototype stuff - Rust has to go trough rebuild+redeploy on every iteration - you're saying that's the same speed ?
- EugeneOZ 10y agoNo. I don't use hot module replacement and I don't like this idea. And I don't prototype things often - maybe once or 2 per year - my contracts are usually long enough. It's all personal, as you see. I'm saying that to implement feature in Rust takes same time as in Typescript or PHP (as PHP is a server side language also and comparison is more illustrative).
- stymaar 10y agoI love JS (pretty unpopular opinion here on HN) and I love Rust also and I'm not convinced using Rust on front-end tasks would have any benefits. Yet, I strongly disagree with you on this point : > Rust is a low level systems programming language, it's very suboptimal for high level front end code from productivity standpoint Rust's type system is wonderful, and it's a real productivity boost. Fortunately people at Facebook developed an equivalent for JavaScript [1] because living without it would be really hard for me now. Furthermore, Rust offers a lot of syntactic sugar that makes it feel like a really high level language (compared to C, Go or even JavaScript pre-ES6 for instance). >it's advantages (mem safety with 0 cost abstractions) don't really matter in frontend It's indeed one of Rust selling point (especially for people coming from a C background) but it's not the only one. My favorite being the data-race free parallelism. I don't know the current status of multi threading in wasm, but being able to take advantage of all the cores of mobile devices could really help front-end frameworks. [1]: http://flowtype.org http://flowtype.org, it's not inspired by Rust but inspired by OCaml, which also inspired Rust.
- rubber_duck 10y ago>Rust's type system is wonderful, and it's a real productivity boost. Rust type system is verbose compared to higher level languages and it lacks a lot of the things that make higher level languages productive. It just focuses on low level code - which is good - but you wouldn't use it in place of C#, you would use it instead of C++, and you don't want to write GUI code in C++ either (even Qt uses JS for the frontend) >My favorite being the data-race free parallelism. Also mostly irrelevant in front end since you're dealing with single threaded event loops and doing parallel work that talks to UI thread is easy. Stuff that needs to do work in parallel can be written in Rust and talk to front end via FFI or RPC.
- cesarb 10y ago> even Qt uses JS for the frontend Only if you use QtQuick. The traditional QWidget API is C++ all the way.
- int_19h 10y agoIf you don't like it, you don't have to use it. The beauty of WebAssembly is that it can be targeted by so many other things. Finally, we can let JS sink or swim on its own, without being propped by an artificial monopoly on the web frontend scripting...