Why I am programming stuff in Rust
I am starting to make more and more little side projects that just don’t make sense in my favorite framework, which as you should know is Ruby on Rails. My Github profile doesn’t even show you just how much work I do in Ruby on Rails because I mostly work on private repositories. I have long been a huge advocate for programming in Ruby because Ruby is nice to program in. Ruby is written for humans.
Some languages, like C and C++, are written for computers. They are designed to allow you to control how the computer operates.
Now Rust, in my opinion, is written for computers AND for humans. The language is designed to help you write the language, making it harder to make mistakes and errors. The compiler is built to help you write good, clean, maintanable code with helpful error messages.
But it goes beyond the compiler, some of the features of Rust make it exceptional.
Take the “”https://whyuserust.com/what-is-a-result-in-rust/“>Result” value. By having this returned by a function, that function forces you to understand that the function could encounter an error, and you then have to deal with that error. You can’t just ignore it and hope everything will be fine.
Memory Safety is one great feature of Rust. Rust provides memory safety guarantees through its ownership and borrowing model, which eliminates common programming errors such as null and dangling pointer references. You also don’t have to worry about memory leaks making your code awful to run.
Performance is another key ingredient in Rust. Rust code can be as fast as C++ or even native C code and it is designed for performance from the ground up. It also has low overhead and efficient memory usage.
Concurrency is also great with Rust. Rust’s concurrency features, such as its lightweight threading model, allow developers to write high-performance, concurrent applications.
It is also easy to learn, with the compiler providing helpful error messages and suggestions for functions that you’ve misspelled. Rust has a syntax that is familiar to C and C++ programmers, and its error messages are helpful and informative, making it easier to learn and debug.
The community is nice too. Rust has a growing and supportive community, with many libraries and tools available, making it a great choice for projects of any size. For example there’s a neat community building a video game engine called Bevy.
The only downside with Rust is that many of the GUI and graphics interfaces are still in fairly early stages of development. A large reason for this is because the core graphics drivers that run graphics cards and window adapters are typically written in C code or directly in assembly and/or were written long ago and poorly documented. This makes them harder to integrate into rust.
While Rust is a powerful language that can be used for a wide range of tasks, there are some challenges associated with using it for graphics. Graphics programming often involves complex algorithms and concepts, and Rust adds its own set of unique features, such as its ownership and borrowing model, which can take some time to learn and understand. So porting complex graphics libraries into Rust has taken some time, but work is definitely progressing.
Although Rust has a growing ecosystem of libraries and tools, and it’s great crates feature, its graphics libraries are still relatively new and may not be as mature as those available in other languages, such as C++. While Rust provides many performance benefits, it can also be more challenging to optimize graphics code written in Rust compared to code written in a lower-level language such as C++ Sometimes you have to do funny things with memory to make graphics fast, which can be challenging for a new Rust developer.
I also like that there isn’t likely to be a Rust 2.0. The Rust language has features built in to extend itself, such as a complex and powerful macro system that allows you to add new features directly to the language using macros.
History of Rust
Rust is a systems programming language created by Mozilla Research and first released in 2010. The language was developed with the goal of providing the performance and low-level control of C and C++ while also addressing some of the most common sources of crashes, errors, and security vulnerabilities in those languages.
The development of Rust was motivated by the need for a modern, secure language for system programming, especially for the development of low-level components such as the web browser. Over time, the language has grown and matured, gaining a strong and supportive community of users and contributors.
Rust has become a popular choice for a wide range of use cases, from developing low-level systems software to developing applications in areas such as web development, game development, and data analysis.
Overall, Rust is a relatively young language, but it has quickly gained popularity due to its focus on safety, performance, and reliability, making it a strong candidate for use in many different domains.
Comparison to Go
Rust and Go are both modern systems programming languages designed to be fast, efficient, and easy to use. Rust provides fine-grained control over performance and can achieve performance comparable to C and C++, while Go is designed to be fast, but with a focus on simplicity and ease of use. Essentially, Rust is harder to start out with, but it’s much faster.
Go has built-in concurrency primitives such as goroutines and channels, making it easy to write concurrent code. Rust also has excellent concurrency support, but its model is more complex, providing greater control and expressiveness, but also requiring more effort to use effectively.
Rust provides automatic memory management through its ownership and borrowing model, which eliminates common programming errors such as null and dangling pointer references. Go uses garbage collection for memory management, which can lead to reduced control over memory usage. This means you could be trying to do a complex function very quickly, and have it interrupted by garbage collection.
Go has a simpler, minimalistic syntax that is easy to learn and read, while Rust has a syntax that is more complex and expressive, but also more powerful. Both Rust and Go have growing and supportive communities, but Rust has a larger and more established ecosystem of libraries and tools.
Both also can compile and run in all kinds of places, but I have found Rustup works very efficiently where I have tried to use it.