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

Ask Lemmy

30724 readers
3099 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

top 25 comments
sorted by: hot top controversial new old
[–] Nibodhika@lemmy.world 3 points 1 hour ago

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.

[–] 30p87@feddit.org 2 points 2 hours ago (1 children)

If you either hate yourself, or somehow manage to forget C/C++, JavaScript, Python and probably some more random languages, then yes. Because Rust is basically just a confusing, illogical mix of all of that. Otherwise, as others pointed out, learn anything else that is - if that's what you want - memory safe, statically typed, yadda yadda yadda, and has a good dependency system, compiler and syntax. Other languages could very well fit much better too, depending on available libraries and features in general.

[–] Nibodhika@lemmy.world 1 points 1 hour ago

While I agree with you that OP shouldn't migrate to Rust, the language is not illogical nor a mix of any of those. There's a lot of stuff that Rust does extremely well that can't be reproduced in any of the other languages, such as Options or Result types. And while it can become confusing when lifetimes get thrown at it as a general rule it's not. Also the compiler messages are so thorough, I don't think I have ever seen anything come close to it.

Rust is not for everything, nor for everyone, but saying it doesn't have it's merits is dishonest.

[–] pinball_wizard@lemmy.zip 5 points 3 hours ago (1 children)

I'm going to answer some questions I'm hearing in you question:

"I'm interested in X, should I learn X?”

The answer is pretty much always ”yes”, to that question.

"Is Rust a good/terrible fit for my project?”

Rust is a solid tool. It'll probably do fine.

[–] CanadaPlus@lemmy.sdf.org 3 points 3 hours ago* (last edited 2 hours ago)

I mean, there's a big gotcha on:

Is Rust a better fit for my project to the point it's worth starting over?

and

Will I like my code better if it's in Rust?

That being said, it's not necessarily a no on either, it just could very well be depending on things not disclosed in OP.

[–] bluGill@fedia.io 4 points 4 hours ago (1 children)

Hating the code is normal. After a while you start to realize all the hard to change decisions you made long ago. What you don't know is if those decisions you wish you had made would be better. There have been a lot of fads over the decades, some of them are complete junk, but the majority have some good points. However all of them have some negatives as well, and there is no obvious answer to which negative is right to accept for your projects.

The ideal answer is spend 20 years learning lots of different options, then find a time machine and go back in time to and restart the project based on what you have learned. Of course at the end of that 20 years you will hear about some new thing you didn't try, but you have to draw the line somewhere. (finding a time machine is left as an exercise for the reader)

Rust is an interesting language with some nice memory safety guarantees. As a C++ developer it speaks to some of the problems I have - but most of my problems with C++ are with 15 year old code from before I was able to use C++11. ( had to put a lot of effort into getting this good with c++ though, Rust is likely a lot easier to learn to my level). The Ada/Spark advocates have long been saying things that really speak to me as well - formally proven code sounds great, though there are others who tell me it isn't as good as the advocates claim. Go has some advocates saying interesting things as well, though they don't speak to the issues I personally have as much it might be better for you.

If you are writing all new code then I would put Rust high on the list. However most programs are adding to something that exists and the friction of writing Rust to existing code is often high enough that I'd stick with what the other code is written in.

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

You sound like a really thoughtful and humble developer honestly. I hope when I'm more experienced I'm like you.

[–] bluGill@fedia.io 1 points 1 hour ago

A part of it is when you get old you realize the "kids" are doing the exact same thing you did 20 years ago, but they gave it a different name and changed some tiny details so they can pretend it is different. The real question is how do you get kids to see this - most don't (including me when I was a kid - and I was aware of the issue and tried to guard against it)

The more important part at my age is to remember that kids today are just like me. Sure the exact style and what is in/out has changed, but kids are the same as we were. I didn't even have the option of a smart phone, but I had my own addictions, and the older generation complained about them.... Sometimes the old people have a point, but often kids these days are just like kids in the past.

[–] Zwuzelmaus@feddit.org 15 points 7 hours ago

I'm starting to hate the code

That's an excellent situation for change.

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

C/C++ senior developer here.

If you don't know, learn Python.

There are very few things python can't do on a hobby level. It's simple and have tons of libraries and tutorials and so on. Also, no need to set up a compiler or so, it just runs straight out of the box. PyCharm is a simple and elegant IDE with debugging, but you could start out with the simplest text editor just to check things out.

HTH

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

I already know Python, JavaScript and Java. I want something without a runtime.

[–] Valmond@lemmy.world 1 points 4 hours ago (1 children)

Just freeze the python to an executable is one way to do it (windows, linux, ...).

But now I'm curious, what's your hobby project about? I mean you can close to chose any language and do anything ... Do you do database? Graphics? Is it supposed to be online? Cryptographics? Gpgpu? Massive multithreading? Large calculations?

If you don't give us more information then we can only tell you to chose the language you like or master the most IMO.

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

It doesn't really need it. I'm sorry for giving the impression that it's some performance critical application lol.

It's just a simple web app backend with a db. Oh and the front end desktop version I wanna build will use tauri (because I hate the thought of bundling a browser) so that's another reason to learn rust.

I guess I just kinda want to make things minimal in the resources they use. Because that's just neat :D

[–] Valmond@lemmy.world 1 points 44 minutes ago

Well if you want to use minimal resources, get Beej's Guide to Network Programming (I highly recommend it for anyone tinkering with sockets in C/C++) and write it in C!

[–] bluGill@fedia.io 1 points 3 hours ago

There is a reason a lot of web apps run on the JVM - while it does have high overhead, once your app is running it is fast and you get some nice advantages. Plus Java has a large system of helpers and libraries. Even though you can do everything in Rust, you will end up writing a lot more code just because in Java you can just download a library to do something while Rust forces you to write it.

[–] sbv@sh.itjust.works 6 points 6 hours ago

Give it a shot!

Rust can be a real pain in the ass: it's like having to solve mini logic puzzles as you're writing your code. At best, it's fun, at worst, it's a distraction and source of frustration.

You can always stop the rewrite if you discover you don't like Rust.

[–] solrize@lemmy.world 1 points 4 hours ago (1 children)

What is the code written in now? What happens if you clean it up? What is the project if I can ask? Everything has a runtime, though some are more complex than others. You might like OCaml which is where Rust got some ideas, or Haskell if you like brain benders. Rust (like C) is for when you need very efficient code, and you incur some pain in order to get that.

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

The code is in Typescript. It's the backend of a web app that's all. Doesn't really need to be in Rust but idk I just want to make something that doesn't use more resources than it needs to. Just to be neat :D

[–] CanadaPlus@lemmy.sdf.org 1 points 2 hours ago

For certain backends, especially the kind that generates static pages, functional code like Haskell works well, and brings a different kind of "cleanness".

Just in case you hadn't considered it.

[–] Nachtnebel@lemmy.dbzer0.com 3 points 6 hours ago (1 children)

That depends from the language you're using now. To really appreciate and understand Rust's borrow checker you need to have some experience in C or similar language. For someone who have used only Python before Rust will look really weird and messy

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

I used C++ and beriefly C before. I suck at both lol.

I get that manually managing memory can be a mess and easily create big problems. Garbage collectors seem like a cool solution but they need a runtime. Rust has no runtime but somehow forces you to manage memory well. Idk how.

But anyway more important to me is that it's a modern language with good devex and tools and no runtime. So it's like if C++ was remade today. At least that's what I hope.

[–] insomniac_lemon@lemmy.cafe 1 points 2 hours ago

Maybe check out Nim-lang? It does have mm (I hear arc/orc are good) though it can be turned off allowing you to manage memory manually.

[–] CanadaPlus@lemmy.sdf.org 1 points 3 hours ago* (last edited 1 hour ago)

Garbage collecting will make your life easier if you don't need (or just want, as a hobbyist) fast code. It's often worth it. Based on your other answers it sounds like you want the conceptual cleanness of not using it, though, which I totally get.

If so, Rust is the game in town right now. The caveat is that you might put all the effort in and still hate your code. And be even further away from finishing it.

So it’s like if C++ was remade today.

It stuck around for decades because short of memory unsafety, there's relatively few things wrong with C/C++. Rust was the first language that managed to do what Rust does, because it's a hard problem. So basically, there isn't any recommended third option.

The way human programmers think is very different from the way processors do. You either insert a runtime that can bring the two closer together, including garbage collection, or expose the difference to the coder. C exposes the difference as invisible memory leaks, segfaults and occasional undefined behavior. Rust exposes it as lifetimes and borrowing, with complicated enough rules most users just change things until it works.

[–] sbv@sh.itjust.works 6 points 6 hours ago

Rust has no runtime but somehow forces you to manage memory well. Idk how.

You tell the compiler which part of your code is responsible for each chunk of memory. Then the compiler gives you errors when you don't respect that. Roughly.

[–] Nachtnebel@lemmy.dbzer0.com 3 points 5 hours ago

If you suck at C, then switching to Rust will not magically change it. C is a small language and learning it is easier than learning Rust. Also, you probably suck at C++ because you started learning it before C.