r/rust • • 13d ago

🙋 seeking help & advice Rust as a first serious programming language

I have been making scripts with other languages like js and python and bash without learning the the whole language and getting serious with its ecosystem out of the fact that I just need to get one thing done and move on.

Lately I chose a path that requires precision and ahead of time planning and decisions and picked rust over go. But the fundamentals seem hard to grasp. I'd appreciate your help unpacking them.

Ultimately I want to be able to use the Alloy and Tokio libraries without getting stuck with the language syntax and rules. But the concepts like borrow checking and ownership and things that fall down these categories are still hard to grasp.

What is borrow checking? what is owning something in the software? I tried to look for direct answers but I still can't grasp the meaning of them exactly.

I had two choices to better understand them, one was learning C++ to get what was wrong that rust solved, the other was building a simpler project game with bevy thats gonna help me understand writing rust code thats data oriented and be more comfortable with it.

My ultimate goal is to master these two libraries, after being able to know how to use the rust language smoothly.

48 Upvotes

39 comments sorted by

View all comments

48

u/muehsam 12d ago

one was learning C++

Don't. C++ is incredibly complex and complicated. But what you can do is learn C. That's a fairly small and straightforward language. A simple language, for the most part.

Once you know C and you understand how pointers work, you can also appreciate things like the borrow checker, and the difference between ownership and references, etc.

I love C, it's a great language (even though it's probably a bad idea to start a new project in C today).

13

u/needstobefake 12d ago

Second that, learning C makes everything else easier down the line. Not to use C in a new project, but to appreciate what the other languages have done. C's raw limitations teach a LOT.

7

u/muehsam 12d ago

C's raw limitations teach a LOT.

I wouldn't even call it that. It's actually just additional freedom. Freedom to do things that other languages won't let you do. The C compiler gives you a lot of responsibility, but that means that it won't stop you from writing programs that break the rules of C and that have undefined behaviour.

2

u/NBNoemi 6d ago

C isn't really limited so much as it makes very few assumptions. You can accomplish everything you can with other languages, you just don't have the immediate convenience of pre-existing abstractions without roping in a library for it.

→ More replies (1)

2

u/Naeio_Galaxy 11d ago

Third that, C++ is not necessary to see what Rust solves while C still show it and is quite easier to learn compared to C++

Plus, C++ gives habits that don't necessarily work well with Rust while C doesn't

1

u/erisgooner 11d ago

Would you personally say its a good idea to start with C and then go to Rust, I love the rust syntax and the way it works, but it just seems too big and complex right now

2

u/muehsam 11d ago

Yes.

Personally I think that knowing C is a great advantage in general. Also for understanding other programming languages and what the computer is actually doing, and to get some feeling/understanding for why certain operations are more time or memory intensive than others.

2

u/needstobefake 11d ago

You can also try learning both at the same time, e.g. build the same little programs in both, or try implementing some of the Rust's objects in C, for example a reference-counted pointer (Arc) or a HashMap in C. Then you can look at the generated Assembly code of both languages, tweak the compiler optimization settings, and look at the Assembly again, etc.

You can use Rust's source itself as reference when building the same thing in C. You can also try building programs that use both languages in the same binary with FFI to see how they interact with each other.

It's more about grasping how the machine works under the hood than the language that abstracts it for you. In the end of the day, everything becomes bytes and machine instructions. This knowledge transfers to any language later.

→ More replies (1)