r/Deno • u/Ooker777 • Jan 01 '24
Why continuing using Deno rather than learning Rust?
When I started my journey, I needed to add a lot functionalities to my little js script. So I need to learn ts. Since I didn't need to work with any Node app, using Deno was not a problem for me. I'm satisfied.
Now I need to deploy it to a webapp. Armed with more knowledge on computer science and software engineering, I wonder if there is any advantage for me to continue using Deno (with Fresh?) rather than using Rust from scratch? Here are the reasons for me to choose Rust:
The switch cost for me is small
My toolkit is richer
I can join into another ecosystem
It can compile to WebAssembly
Deno is written in Rust
I can have more chance to broaden my knowledge and open my mind
Another language to put in CV
I don't really have any reason to continue using Deno, except the convenience of continuing using TS. Is there any thing that I miss? Like, if you still use TS with Deno, then what makes you not make the switch?
7
u/xroalx Jan 01 '24
If you want to use Rust then... use Rust.
Languages are just tools. Pick the tool that can do what you need and fits your needs, ideas, desires, whatever. If it's Rust, it's Rust. If it's TypeScript with Deno, then be it that.
You already have a good idea of what you're losing and what you're getting with that switch. Go for it.
1
u/Ooker777 Jan 01 '24
I mean, is there any thing that I miss? Like, if you still use TS with Deno, then what makes you not make the switch?
3
u/Left-Till-7530 Jan 01 '24 edited Jan 01 '24
Nothing, go for Rust, learn it by yourself! Theoretically you must be able to solve any computer science problem with any Turing complete language, in practice it may take a hundred years with the wrong language.
Spend a whole afternoon solving whatever problem you have in both languages, then tell us 🙂
1
u/Ooker777 Jan 01 '24
can you share about your experience? If you still use TS with Deno, then what makes you not make the switch?
5
u/Left-Till-7530 Jan 01 '24
Money, you can start making money with TS from day 0, you need a couple of years of experience in systems programming to get into a Rust shop, go and look for a job opportunity with Rust, probably it will not match your professional profile.
Most of Rust people is into opensource or $BigCorp with a CS impressive career.
The problems solved by Rust are way beyond simple apps development.
2
u/xroalx Jan 01 '24
I use TS with Node professionally and mostly for personal stuff as well, because I already know it well, and despite getting on my nerves at times, it does everything I need in a way that, for the most part, suits me well.
I know and have experience with C# but I don't feel like switching to it would really give me any benefits. It feels a bit wild-westy, much like JavaScript, but with JS/TS I at least am already familiar with the wilderness.
I know Go and would use it for smaller pieces where memory and performance might be of more importance, e.g. in lambdas, but I've tried writing a large app with it and didn't like it. So, no real incentive to switch completely from what I already know either.
PHP has always given me a very bad DX, despite being the first language I learned and having a pretty nice modern feature set, using it is just pain for me.
I'm interested in Elixir and plan on diving deeper into it. I probably won't switch to it fully either as my professional career does not require it at all so far, and my personal projects can be run on a potato and aren't my livelihood.
Languages are just tools, luckily for us devs, they're all tools that can produce the same final results - web apps, servers, whatever software you have - with various degree of productivity, performance, and various approaches to solving problems. Thanks to that, you have the option to pick not only the one tool that's right for the job, but also the tool that excites you the most, so really, just go for it!
2
u/pizzacomposer Jan 01 '24
JS/TS is “dynamic” while Rust is “static”.
Generally speaking, dynamic languages are more “flexible”, which really means it’s faster to write simpler things, and faster to change existing things.
Again, generally speaking, static languages are less “flexible”, slower to write simpler things, slower to update existing things. The trade off though, is that compiled static languages are typically faster, more accurate, less error prone.
Backend engineers who are familiar with static languages their entire career typically underestimate the productivity gains from working in dynamic languages as they are quite adept at writing in their preferred language and don’t see the benefit, but like for like, a small to medium sized application will require less lines of code in a dynamic language.
It is totally reasonable to write something in Deno/TS then migrate it to Rust, in fact, this is probably the optimal pathway to building something effectively.
The only thing to consider, is that if you anticipate that the application is still in a discovery phase and is subject to change, that I would consider holding off a bit till it becomes more stable. Additionally, Deno/TS isn’t as inefficient as Node. While it won’t be as fast as a Rust application, it’s by no means slow. You should also be wary of “busy work”. What outcomes does a re-write in Rust deliver end users? If you don’t have any end users then maybe a re-write isn’t what you should be focusing on.
3
u/guest271314 Jan 01 '24
Additionally, Deno/TS isn’t as inefficient as Node.
That one needs some explaining.
1
u/pizzacomposer Jan 02 '24
Everything outside the V8 engine is more performant than in Node given it is all re-written in Rust.
I’m not going to expand further, I suggest watching a video by Ryan Dahl on it, he does a much better job of describing the intricacies.
1
1
u/guest271314 Jan 02 '24
Watching videos won't verify anything. Tests will. To begin we have deno at 133 MB, node (nightly) at 96.6 MB. Granted after strip deno is 93.5 MB. We will need to test API's 1:1 where possible to make such a determination conclusive. I don't have a preference for either, so I am well-suited to perform such tests. I use bun, tjs, and qjs, too. All of those JavaScript runtimes have their uses. The last time I checked deno is slightly faster than node as a Native Messaging host, though I have changed the source code for node version since then https://gist.github.com/guest271314/fb8969a956a873e495b890a42ac0d731 bun and qjs are faster than deno and node
[{ "nm_qjs": 0.2468439999997615 }, { "nm_bun": 0.2530850000003726 }, { "nm_deno": 0.34589599999971704 }, { "nm_nodejs": 0.36726300000011924 }]1
u/pizzacomposer Jan 02 '24 edited Jan 02 '24
I said that Deno isn’t as inefficient as Node, then you start telling me about Bun and qjs. But you acknowledge that Deno is faster than node via your own test parameters.
But you also mention that Deno has a bigger footprint than Node. I can’t tell you why that’s the case, and I didn’t realise that, thanks for letting me know.
What do you want me to say to you? That wasn’t my statement, and I don’t care that bun and qjs are the fastest.
I should have said Deno/TS is slightly more performant than Node, is that better?
Ryan Dahl states that there are issues with the codebase itself that make it difficult to maintain and improve on.
1
u/guest271314 Jan 02 '24
If you claim A is more efficient than B you need to include tests to run for somebody other than yourself to reproduce your claims. Watching a video is not going to run any code to reproduce claims.
Nobody is exempt from being vetted. The way the scientific method works somebody else has to verify claims, preferably someboy that does not have an interest in your claims being true and correct.
1
u/guest271314 Jan 02 '24
This is what I mean
Now watch. ..., this how science works. One researcher comes up with a result. And that is not the truth. No, no. A scientific emergent truth is not the result of one experiment. What has to happen is somebody else has to verify it. Preferably a competitor. Preferably someone who doesn't want you to be correct.
- Neil deGrasse Tyson, May 3, 2017 at 92nd Street Y
1
u/Ooker777 Jan 02 '24
It is totally reasonable to write something in Deno/TS then migrate it to Rust, in fact, this is probably the optimal pathway to building something effectively.
can you elaborate this part? I get that if the app is still in a discovery phase, then I should hold off until it becomes more stable. But when would you decide that the app is stable? And if it's stable, then what's the point of rewrite it in Rust? By definition, stable means changes comes infrequently and not significantly. I assume that you only need to add another modules and functions. At that time, your incentive to rewrite in Rust is small, since the cost to maintain the old code is lower than the cost to rewrite. Only when you have a significant change that you have to nearly refactor all the main code that rewriting everything has a lower cost, then you can migrate to Rust?
2
u/pizzacomposer Jan 02 '24
There are different ways you can split up the code.
One way is to keep your web-facing code written in Fresh, and your services that demand performance be written in Rust, and called from the Fresh application.
You can also use Foreign Function Interface, where you can write code in Rust (or other languages) and call it from Deno. That makes it easier to co-locate the code in a single repository.
As for a full re-write, I don’t think that’s what I envisioned when I made my comment. A web facing application changes frequently, so you need flexibility. From routes to user interfaces, all better maintained in Fresh. But if you have some sort of heavy or critical calculation it’s best off living in another language.
I know it’s hard to see “when do you decide it’s stable”. But consider that if you’re running a function and you have millions of users, and optimising that function could save hundreds of thousands of dollars to the business, then a re-write in Rust/Zig/C is justified. I guess what I mean by stable, is that the code itself is making the company money, it doesn’t change often, and a significant monetary outcome would come from a rewrite for a given part.
If you’re capable in Rust or similar and want to write it for a living, then instead of building POCs you’re better off joining a company where you’re getting paid to write it to solve big expensive problems.
I’m not trying to gate-keep you from learning Rust if you’re keen, you should follow your passion. But if you’re trying to build product then Rust is a distraction.
Hope this helps.
1
4
u/guest271314 Jan 01 '24
I've been wanting to dive in to Rust for quite some time. I do the bulk of my testing and experimenting on a live Linux distribution running on a temporary file system. Rust toolchain is over 1 GB. If I am able to complete getting the toolchain without running out of disk space then if I try to install a single crate, e.g., tokio, the device will run out of space.
I get just fetch deno, call strip to go from 133 MB to 93 MB, and go. If I want to use WASI or WASM there is WASI-SDK and wasmtime, which still takes up less space than the default Rust toolchain.
So for me it is a matter of being able to run Rust on a live Linux CD/DVD/USB and install Rust crates, which currently is not feasible, and since I've brought this up before to the Rust maintainers and nothing has changed, I don't see this as changing.
2
u/turboladen Jan 02 '24 edited Jan 02 '24
Interesting. How much memory are you running on? I was curious, so I booted up a live EndeavourOS SD card (using whatever their default windowing env is) on a 2013 MacBook with 16GB of memory (arguably that’s a hefty chunk for the time), installed Rust and copypasta’d one of tokio’s http server examples (which required a number of extra deps) and the build directory’s total is at 290MB. The .cargo directory and children are only 44MB. The whole system is only using 1.3GB of memory.
Are you able to tell what’s taking up all your memory?
2
u/Top-Aside-3588 Jan 01 '24
If you have a target project, go for a rewrite in Rust. At least a proof of concept. You will pretty quickly get your answer, and I can't tell you which one you will end up preferring. There are people who do web front ends in Rust.
Personally, I am a backend programmer, and I have been using Deno for pretty much everything I have done for the past couple of years rather than Go or Rust. It is plenty fast, easy to hack, easy to read my own code a year later, and the --allow-write flag has saved my butt on a couple of occasions where I would have otherwise written to unintended areas of the file system. Pure source installs (just copy and run, no compile) is nice too. But you are doing web stuff, so ... your mileage may vary.
As a systems programming language, Rust is pretty expressive. But TS is a multi-paradigm language that lets you do functional, OOP, aspect-oriented, or pure hackery as you see fit. With Rust, you have somewhat more limited ways of solving problems, and you generally have to design more up front. Rust is less suited to quick hacks and trying things out and spitballing code. The trade off is that you get pretty tight control over what your program is doing, and super quick execution.
On the other hand, you may prefer the expressiveness and the lightness of TS. And don't be fooled - TS execution can be as fast as C - if you can stick to Asm.js style code.
Another valid use of Rust would be to identify areas of your code that are performance bottlenecks and convert those to webassembly, assuming you can't make them fast enough with simple Asm.js tricks.
2
u/guest271314 Jan 01 '24
It can compile to WebAssembly
Multiple programming languages can compile to WASM, including JavaScript https://github.com/bytecodealliance/javy
2
u/Strobljus Jan 02 '24 edited Jan 02 '24
Rust is low level, meant to be used in the same way that C++ is. Keywords are performance, optimization and resource efficiency. Predictable behavior, stability and customizable memory management. All at the expense of ergonomics and DevEx.
JS/TS is high level, and meant to be ergonomic for developers at the expense of performance. Keywords are ease of use, useful abstractions, velocity of programming. Getting shit done, delivering stuff.
Now, is it possible to cross the boundaries and use the languages outside their intended domains? Absolutely! Can it be a fun exercise? Sure! Is it a wise choice when building something important? Almost certainly not.
1
u/bucketpl0x Jan 01 '24
If making a web app, the front end is going to be using JavaScript. One reason to just use Deno/TypeScript is to have your full stack using the same language. It is easier to switch contexts between working on the front and back end that way. If you need to eventually employ others, it will be easier to get devs that can work on the full stack if you are just using one language. There are more TypeScript developers than there are developers that know both Rust and TypeScript.
1
u/turboladen Jan 02 '24
I’ve been using Rust, both personally and on the job, for about 6 years after spending most of the previous 10 years doing Ruby/Rails. Like others have said, Deno (or more generally, TS) and Rust are tools for the job, where one might be more pleasant or convenient or easier or predictable or robust or flexible for the job at hand. And probably like many professions, after a while you land on some personal preferences for characteristics of your tools. In this case, they’re both great and you’ll get a lot of use out of either of them.
For my part, I really enjoy Rust’s compiler and type system; I’m regularly amazed at how I can break my build while refactoring or redesigning a codebase for weeks, then once it complies, it just works. For me, the general feeling (and I repeat “general”) is that I might spend a tad more time up front with Rust, but I have a much more pleasurable experience in the long run. The type system in Deno/TS is great, but IMO it’s a notch below Rust’s. …which also has its tradeoffs—many people absolutely hate the stringency of Rust’s type system. Historically, Rust was marketed as a “system” language, and it still has this feel in a lot of portions of it, which would probably contrast with Deno and its stdlib—again, for better or worse, depending on what interests you and what you’re working on.
Learning Deno (or, again, more generally, TS), definitely has a ton of benefits, given the prevalence of TS in software. You will definitely get a lot mileage out if learning TS, and IMO if you’re gonna do TS, Deno takes the cake. If you want to work in the web realm (backends or frontends, obviously) you can’t really go wrong by continuing down the Deno path (although some familiarity with Node to go along with that won’t hurt). As you know, you can do all these things in Rust, but it’s a different experience, and one that might require more (or less!) work, depending on what you’re doing. For my part, I still reach for Rust in many of these cases, just because I enjoy working in it more than I enjoy working with Deno, but I only know that because I’ve spent enough time using both. (And they’re both fantastic)
Tl;dr why not both? :)
0
u/burtgummer45 Jan 02 '24
If you are doing server side stuff, JS async is easy, Rust async is painful. And to any rust fanboy who is going to say "Ackchyually, rust async isn't that bad", I say, yea right.
1
17
u/Left-Till-7530 Jan 01 '24
Not sure how long you are in the industry, but I think you are missing a big point there, JS and Rust are two completely different languages with 2 different purposes, one is a language mostly used for the web and the other one is a low level general purpose systems language.
Working in one or another is a matter of your current problem and content: you are not going to do Browser DOM events scripting with Rust, you can’t write a Linux or a Windows driver in JS.
You will work with both or one of the two during your career, but they are complimentary, maybe you don’t need one of them some time because your job doesn’t requires it.
In summary: don’t compare oranges and apples 🙂