Needing some advice for a beginner

Hi everyone. Happy Christmas :).
I'm new to this forum and I enrolled it because I have some concerns. Maybe it's because I tend to think too much, or idk, but I can't decide my path. I'm trying to start programming again after some yearsand I'm interested to make physics simulations, TUIs, GUI apps, maybe a game with sdl or idk, whatever comes to my mind. I have a repo with some code I made so you can see I have a low level, mostly: My repo. I also made a webpage with some basic numeric simulations in typescript webpage repo using a little bit of help witth AI (mostly css stuff), as it was my first time making a webapp. The thing is, I'm not sure if I'm going the correct path with Rust or I'm making a mistake. I know I could change languages and so if I don't feel good with it but... Could you help me? Is the rust code I made good enough?

1 Like

I think Rust in general is nice to use because it learned a lot of lesson from other (older) programming languages which makes it feel (atleast for me) that someone really put lots of thought in it. Some examples would be explicit handling (no try … catch, you can‘t just ignore possible errors), expressiveness (algebraic type system, enums are really great), a small standard library (see Python), memory safety (ownership, which also makes concurrency a lot safer), a strong focus on performance (mostly comparable to C I think, far better than C#) and so on.

To be more specific, I think Rust is well suited for physics simulations because of its expressiveness and performance (if your simulation gets a bit more complicated) aswell as TUIs, I have tried the ratatui crate which worked pretty well for me (except you try to use custom ANSI color „images“, which you probably don‘t). For games, there‘s ggez or a more framework-like game engine called bevy (I can strongly recommend it).
GUI is ok but probably mostly not comparable to React (see here.
For web, you can use WASM which Rust compiles to, which is more performant than JS and supported by all major browsers.

So, as an (opinionated) conclusion I‘d say yes, mostly.

I have written enough at this point and let the code review be subject for other people.

Wow. Such a detailed response. Thank you very much. That were some things that made me be interested in Rust, but everyone says you should learn C or C++ in order to appreciate what Rust does and so on, so I wasn't sure if I was trying to "kill flies with a cannon" or maybe I was trying to point to far and something more like C# would be enough. Idk. Anyway, thanks a lot :slight_smile:

Thanks. Since I got to know C/C++ a bit from the Rust perspective, I don't think learning C/C++ is worth it. I really appreciate that I was able to make the "better" (opiniinated ofc) choice first,
as opposed to ten years ago

1 Like

Did you have prior knowledge of programming before? I mean, I don't know anyone who has started with rust from zero or near zero

This question comes up a lot. Personally I see no reason can't be a first language for a raw beginner at programming. Printing "Hello World" in Rust is about as simple as any other compiled language. From their our beginner canoe introduced to variables, operators, expressions, etc, Then move on to if/else and loops and matches. Then functions, structures, methods, etc. In a slow progression as one would in any other language.

After all it has been said that "All of programming is just sequence, selection and iteration. Which can all be demonstrated to a beginner with Rust as well as anything else.

The problem might be that there are precious few tutorial resources that teach Rust assuming a raw beginner as the audience.

Back in the day I was introduced to programming with BASIC and we were expected to become fluent in assembler in those same months. So I don't see that an introduction to programming with Rust would be any more difficult.

1 Like

Sorry for the confusion but that wasn't my question. I didn't explain it correctly. What I was asking was if it is a good path or maybe I should use something more battle tested in areas of raw computation, graphics using libraries, etc. Sorry for that. Regarding what you've said, I think languages are tools and with enough perseverance learn whatever language is possible. But thanks for answering :slight_smile:

Well, one of the things I can recommend is lurking in this forum :'D I wish I had done this when I started learning rust and trying to make things in it like 3-4 years ago. By going through what problems people come across, what solutions more experienced people provide, or even trying think about what the probable solutions might be, gives you a much deeper insights than trying to just make things on your own. From your codebase, I think you should start with setting up proper tooling, run cargo fmt and cargo clippy (if possible with more stricter rules like pedantic and nursery) to check how idiomatic your code currently is. AI is pretty helpful in providing more general advice like how to set up rustup toolchains and cargo, and project's Cargo.toml and other config files (the models are unusually bad at writing rust code, in my experience).

Thank you very much :slight_smile:. If I'm honest, I did basic Java and Matlab at uni (I'm physicist and a highschool teacher here in Spain) and it's like everything is telling me I will fail because 8 years have passed and this is more complicated, etc. And our course I will search things here. It's one of the first things I did hahaha

1 Like

I implemented some simple simulations of nonlinear dynamical systems. Specifically, an inverted pendulum on a cart (my background is in control engineering). Nothing super complex, but I had fun doing it in Rust as a learning experiment. I’m not sure what kind of physics simulation you have in mind, but in my opinion, Rust has enough high-quality libraries. From the rather low-level numerical linear algebra (nalgebra, ndarray, both somewhat mature) to ODE solvers (diffsol) and easy-to-use graphical libraries (egui). That said, I believe you’re on the right path. However, it may be a long and, at times, painful one.

I read through a Python book („Python for beginners“) (one year ago), didn’t know what to do and learned some very basic C++ (I programmed a tic-tac-toe, so I basically knew the syntax), meaning that Rust is the only programming language I ever really learning, which I, as already mentioned, consider a huge privilege. (As opposed to the past)
So no, I didn‘t start completely from scratch, but I learned most of the concepts, speak advanced pointers, async, stack vs. heap, generics, traits, concurrency with threads, functional programming (at least a bit). That meant that reading the book needed a lot of concentration from my side to really understand it. So I would say that learning Rust „nearly from scratch“ is possible, but definitely more demanding.

I was thinking in things like that pendulum, electric, magnetic and gravitational fields and that sort of things. Or maybe molecules in a box being in contact with hot and cold plates. Maybe trying to model a fermi non-relativistic gas. Idk, going bit by bit, maintaining my physics knowledge and also thinking about everything being didactical, so I can show animations to my students. For now I want to study DSA and later I want to build Conway's game of life and that sort of things. Just bit by bit

Wow. It sounds impressive, to be honest. What I've seen about Rust and the basic things like ownership, borrowing, etc., I think it makes a lot of sense to me. And that's one of the things that made me be interested. Also cargo was impressive, but I mean, Go and C# also have good tools (I know they're higher languages). Idk, I just thought of Rust as the kind brother of C++, you know? Someone that instead of letting you fall through a cliff makes what it's able to do to avoid it. These are the things that attracted me but I wasn't sure I would be able to handle it. Also, as there's not much beginner bibliography and so...

I really wonder if that is true. What is it that is supposed to make a language "higher" now a days?

I detected that you may have two different questions here:

  1. Is Rust capable of doing the graphics, physics simulations etc that you want to do.?
    To which I would answer totally yes? As much as C++ or whatever.

  2. Are there libraries available in Rust that make doing said graphics, physics simulations etc easier?
    I have no idea. Depends what exactly you want to do,

It's a very good question. I've always read and heard that they are higher languages. I mean, it's what I've been told. I suppose that you need to be able to compile to binary code and run the program without any runtime installed and also to be able to do arithmetics at a bit level. I think that would be a lower language. Idk

Answering the first point, the thing is more about which path would be the path of least resistance in terms of having to fight with tools and libraries. Not the difficulty of a language, which I consider it's more of a subjective thing in the end.

And to answer the second, in terms of physics libraries it would be nice to be able to make mines because I know about the physics behind and that's a way to start to model the behavior. And then, in terms of graphic libraries, I've seen SDL having official bindings, Raylib and SFML also have bindings, there's OpenGL and Vulkan and there's the Bevy engine if I want to use an engine. Idk at which state are those things and that's one of my concerns about which "path" to go.

Anyway, thanks for taking the time to answer me. It's a pleasure to see that there people able to help and not treat me like a stupid guy that makes the same question as 43 thousand people today.

"high level", "low level", it all seems very blurred to me. Certainly Rust enables low level operations like dealing with actual memory addresses or interacting with bits and bytes in the I/O of device drivers and such. These are things one cannot do in a high level language like Python or Javascript. On the other hand Rust and C++ provide features to rival anything such high level languages have.

Anyway, I don't know much about the things you want to do. But recently I needed to create real-time data visualisations. The first I did using the slint crate Slint is meant for creating GUI's with buttons, check boxes etc but I used it for 2d animated graphical drawing. The second I did using the wgpu and wint crates. WGPU is a API for 3d rendering accelerated with the GPU. Think. modern OpenGL. The beauty of all this is that these things all run on Linux, Mac and Windows, and in the web browser!

I guess at some point you have to focus on something you want to do, roll your slivers up and start on it. Of course with that focus you can ask more specific questions here as to how to start and proceed.

I've read about slint and all of that. It seems interesting and the fact of being able to cross-platform is great. And I also think the line between high and low is blurry. Rust and c++ being able to do all things and also with rust having yew, leptos, dioxus, etc., I think it's a fascinating new world opening in front of our eyes

I think saying that Rust is a systems programming language makes more sense than talking about "high level", "low level". But personally for me the fact that Rust and C++ makes the explicit distinction of value types, and references or pointers, somehow justify the term low-level. The Wirthian languages including Nim had primary just the var parameter in functions to indicate the mutability of a parameter. And languages like Ruby, Python, Java do typically not make the distinction of direct value types or references at all. The explicit use of "&" for references in function signatures and for types makes it easier to see what is actually going on, but introduces some form of "noise", and personally I often get the use of "&" and "mut" wrong for the first prototype, so a second or third compiler call is often required to get a successfully compilation.

I suppose you're totally right. I'm not so sure about everything you said because I'm still learning basic things but I think you're right. Thanks for spending your time answering :grin:

Just throwing this in.
If you plan of doing "simulations" then you are also going to need to learn some of GL languages. Shaders do a lot of the work in simulations.