this post was submitted on 07 Apr 2025
40 points (95.5% liked)

Ask Lemmy

30871 readers
17 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 [email protected] or [email protected]. 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 [email protected]. 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 [email protected] or [email protected]


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
[–] [email protected] 4 points 6 days ago (1 children)

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.

[–] [email protected] 2 points 6 days ago (1 children)

Hmm. Well I tried to learn C++ as my first programming language when I was 12 so that's probably the reason lol. I was just bad at everything at that time. I moved onto Java next, but maybe I should revisit C++.

But if I had to name specifics these come to mind right now:

  • Using code across multiple files or libraries is really annoying. The preprocessor directives, I kinda get them but there's always something that breaks and I don't understand why. Also why isn't there a package manager or something like that? Hmm maybe there is nowadays but I don't know if there was back then
  • Still don't know what a link error is or why it would randomly show up and then disappear if I restart visual studio
  • I know this is a meme but long hard to understand error messages in the case of C++ and no useful error messages at all in C
  • In C did you know that the order of items in a struct matters? I didn't until I spent an hour debugging a segfault.
  • Obviously C doesn't have strings. Accomplishing even the simplest things in C feels really hard. Like you're on your own.

I'm very sure all of these can be summed up as me being bad at the languages. Skill issue etc. and it's true. I am bad at both.

But the point is there's a lot of things I don't understand and that seem unintuitive to me. So it's not fun, so I don't use it. If you gave me a programming problem for fun and told me choose your language I would never choose C++ and certainly not C. I'd use Python, JavaScript or Java because they feel more fun to use and I can see progress faster. Same for my new projects. I've never tried to make anything more complicated than a command line program in C++ or C.

At the same time I understand that higher level languages abstract a lot of things away from you and I really do wanna get better at understanding those concepts.

Anyway thanks for attending my therapy session.

[–] [email protected] 3 points 6 days ago (1 children)

You might want to take a look at C/C++ again at some point, you didn't mentioned a single thing that I expected, I expected you to complain about memory allocation, double frees or stuff like that, instead you touched on lots of very accurate pain points for C/C++ that people who use it for years feel.

  • Preprocessor directives: I assume you mean macros like #ifdef _WIN32, macros will change the code before it gets compiled, so they allow you to write meta-code, as in code that writes code. Rust takes this to a whole new level, so you might want to understand the basic concept before looking into advanced Rust. That being said, I don't think these are complicated in and of themselves, nor do I think you're having problem with understanding what they mean, and it's more likely a question of why, and the answer is that some stuff should happen at compile time, e.g. checking if you're on Windows or Linux do define how you deal with paths or something. But the same can be extended to knowing if a given feature is enabled so you can compile only parts of the program. The lack of package manager is a pain, but C/C++ predate lots of those concepts, and there have been lots of attempts. Also if you're using Linux your system already has a package manager so using some common standard like CMake for your projects makes it all "just work" (most of the time)... But yeah, this one is a pain, no question about it, and Rust solved it properly.
  • Essentially the compiler couldn't find something, they shouldn't appear randomly and that's perhaps a VS bug, never used VS for C/C++ development so I'm not sure on that one, but whenever I had link errors I was forgetting an include or a library on my CMake.
  • What do you mean by errors? Compiler errors? You learn to read them with time, but yeah, Rust compiler errors are much nicer, although they can lead you into a rabbit hole by suggesting changes you shouldn't use.
  • I do know that, it's not intuitive if you're thinking on a higher level, but if you think on low level stuff it makes absolute sense. I can't think of why this would have caused you trouble needing debugging though, you could be occupying more memory than necessary, or you could be running into problems with unions, but I can't think of why the order of a struct would make anything crash unless you're naively converting between types by casting a pointer, which is a red flag on its own.
  • Well, C doesn't need strings, what is a string? It's just an array of characters. C tries to not impose anything on top of the very basics, so it makes sense it doesn't have a string type, appending to a string or to an array of numbers is essentially the same, you just deal with strings more commonly. And this forces you to think on what you're doing, e.g. my_str += "something" sounds like a very simple thing, but under the hood you're allocating an entire new string, copying the content from my_str into it, appending something and then deleting the old one. C forces you to do that stuff manually so you have to be conscious of what you're doing, string operations are not cheap, and you can gain a lot of performance by simply preallocating all you'll need from the start. Rust is similar here, while they do have a String type, they make a very big difference between it and a slice of a string, so that makes you conscious of when you're doing heap stuff.

I spent years with C/C++ as my main language, and I can tell you that I would also not choose it for a random project. However I would also most likely not pick Rust either. Python is my go-to for "I need something quick". Rust would be my go-to for "I need something robust", or "I want to make sure this will work as intended", it will mean a more tedious development cycle with a very slow iteration (much slower than C/C++, e.g. adding an enum value can mean lots of fixes on Rust, because most places where you're dealing with that enum would fail to compile because you're not taking the new value into consideration), but it will mean that every step will be solid (if it compiles after adding an enum value, I'm sure it's being considered).

Do learn Rust, it's fun and personally I see a LOT of future in that language, but it also abstracts some of the concepts away while still requiring you to know them, e.g. heap/stack. I think learning C/C++ for the core concepts is better, but if you know those concepts Rust is a better language overall.

[–] [email protected] 2 points 6 days ago

Thank you for your wisdom. I hope one day I can be as knowledgeable as you people.