this post was submitted on 07 Apr 2025
25 points (100.0% liked)

Ask Lemmy

30724 readers
1900 users here now

A Fediverse community for open-ended, thought provoking questions


Rules: (interactive)


1) Be nice and; have funDoxxing, trolling, sealioning, racism, and toxicity are not welcomed in AskLemmy. Remember what your mother said: if you can't say something nice, don't say anything at all. In addition, the site-wide Lemmy.world terms of service also apply here. Please familiarize yourself with them


2) All posts must end with a '?'This is sort of like Jeopardy. Please phrase all post titles in the form of a proper question ending with ?


3) No spamPlease do not flood the community with nonsense. Actual suspected spammers will be banned on site. No astroturfing.


4) NSFW is okay, within reasonJust remember to tag posts with either a content warning or a [NSFW] tag. Overtly sexual posts are not allowed, please direct them to either !asklemmyafterdark@lemmy.world or !asklemmynsfw@lemmynsfw.com. NSFW comments should be restricted to posts tagged [NSFW].


5) This is not a support community.
It is not a place for 'how do I?', type questions. If you have any questions regarding the site itself or would like to report a community, please direct them to Lemmy.world Support or email info@lemmy.world. For other questions check our partnered communities list, or use the search function.


6) No US Politics.
Please don't post about current US Politics. If you need to do this, try !politicaldiscussion@lemmy.world or !askusa@discuss.online


Reminder: The terms of service apply here too.

Partnered Communities:

Tech Support

No Stupid Questions

You Should Know

Reddit

Jokes

Ask Ouija


Logo design credit goes to: tubbadu


founded 2 years ago
MODERATORS
 

Feel like everyone's been telling me it's the best thing since sliced bread. I'm just a hobbyist with like a single big project I'm maintaining but I'm starting to hate the code and idk maybe I should rewrite it in rust. Idk

you are viewing a single comment's thread
view the rest of the comments
[–] Nibodhika@lemmy.world 7 points 9 hours ago (1 children)

Let me start by saying I love Rust and think it's great. I've been writing some personal stuff in Rust and it's all that I've been looking for.

However there is some stuff you said that makes me think Rust won't be something you would fully appreciate Rust. Firstly every project, regardless of language, when it becomes big it becomes a hassle to maintain, especially if you're not experienced enough to have set up a good architecture from the start.

But more importantly, a lot of Rust benefits are stuff you didn't mention, and some of the stuff you mentioned is not that important.

  • Speed: Performance gains will be minimal, most of the time your server takes on an API call is read/write disk/Network, and that takes as long as it takes regardless of language. Sure synthetic benchmark will tell you it's twice the speed for a hello world, but the moment you start relying on outside stuff the line gets murky.
  • Less resources: Again, unless you have at least 10 instances of your service or are trying to get it to run in very minimal hardware conditions, you're not likely to see any meaningful improvement. Sure your service now uses half the amount of RAM, but the hardware where you're running it likely has a couple orders of magnitude more RAM than that anyways.
  • Garbage collection: You say that like it's a bad word, but at the same time admit to have problems with C/C++, whose main differences are related to that.
  • Compilation: I don't think you're taking compilation into consideration, from line change to retest we're talking a couple of minutes depending on the change. That can be annoying really fast, especially if you don't understand the reason. Also, the Rust compiler is EXTREMELY pedantic, it will not let you compile stuff that you think should work because there's an edge case that you've forgotten to consider because it's not something you cared about, e.g. you can't have global mutable variables because that can cause race conditions on multi-threading applications.
  • Security: you didn't mention this but it's one of the largest advantages of Rust, things like the Option or Result types as well as the match statements and the borrow checker are amazing and unmatched by anything else out there.
  • The Rust price: Rust is not free, you just pay beforehand, you win execution time at the expense of compiling time, you save on runtime errors at the expense of pedantic code checks, etc, etc. Rust is excellent if you understand why, and are willing to pay that price. Rust is for people who when the compiler says "you can't do this because it will cause problems with X edge case" say "of course! Thanks!", if you think "ugh, that's never gonna happen, stupid compiler" then it's not for you. To add to that, Rust can become quite complicated because of it.
  • A different way of structuring: Rust does not have classes or any OOP paradigms, it's different from other stuff you've used and requires changes in how you structure your hada and application. Whether that's for the best or not is very personal, but it's definitely different.

Finally I would like to finish up saying that Rust has the most excellent documentation: https://doc.rust-lang.org/book/ read that, then maybe do these https://github.com/rust-lang/rustlings if you get to the error types and are not drooling over the language, it might not be for you.

[–] droning_in_my_ears@lemmy.world 1 points 6 hours ago (1 children)

Thanks for the detailed write up.

One more reason I might not have mentioned is that Rust is low level and has a good developer experience. At least I heard. The whole compiler is your best friend thing.

Idk I guess I'm hoping it will teach me those concepts better without making me frustrated in the way C++ and C did. Those feel like they're excellent languages that were no doubt revolutionary in their time but are now lumbered with legacy and unintuitive things. Maybe it's false hope. Rust certainly looks intimidating but everyone says the tools and docs are amazing.

I've decided I'm gonna learn it for sure. Whether I rewrite the project or not I'll decide later.

[–] Nibodhika@lemmy.world 1 points 2 minutes ago

Yeah, that's a good approach, learn it and it's one more tool under the belt.

That being said, I think you need to have some good level of proficient in C/C++ before lots of the Rust things make sense. I'm not sure what frustrated you about C/C++, and if you'd like to ask questions about that I'm happy to try to answer them. But a lot of concepts are the same just shown under a different light. For example, on C/C++ you chose to use stack or heap by declaring variables or allocating memory and storing it in pointers, in Rust you don't allocate memory directly, instead you use types that store information on Heap, e.g. Box. I think that's a lot less intuitive, and requires you to have a good grasp of heap/stack before it makes sense, but it prevents you from doing stupid stuff you might do accidentally on C/C++ like store a pointer to a stack object after it goes out of scope.

But I might be wrong, it might be that for me all of that made sense because I knew C/C++ but that to you it will make sense regardless, and might even teach you those concepts that are useful on C/C++ too.