A C++ Developer transitions to Rust
As a fan girl of the programming language C++
A majority of my low-level programming projects have been done in this language. To be honest, even some of my relatively “high” level programming projects have been done in C++17 just because I loved programming in this language so darn much. After having been stagnant in programming for a decent amount of time, I decided I wanted to learn a programming language that was way more modern. I have programmed in other relatively high-level languages as well, such as Crystal. I honestly prefer this over Python. I just wish it had more libraries. As for relatively low-level programming languages, none of them really caught my eye.
Alas, after working with a small game engine for a few weeks, I wanted to write more cross-platform code. I didn’t want to write the same code twice and juggle dependency management hell across multiple systems. So I used vcpkg. Which, in retrospect, was like putting a band-aid on something that shouldn’t exist in the first place. And even then, I still walked away with, yeah, I still love C++.
Fast forward a bit, and I realized that a majority of the open source projects that I wanted to contribute to were using Rust. So I thought, hey, I may as well try it out, since I didn’t think I’d like it anyway. I didn’t like Zig beyond the conceptual level, so I thought Rust would be the same.
Why I am now a rust fan girl!
To force myself to learn it, I rewrote my entire website’s static site generator. I ported all the Bash code over to Rust from scratch, mostly because I already knew the architecture and just wanted a project to learn the language with.
And honestly, after learning the basics of Rust, I prefer it to C++17 for most things. I think its memory management model can make certain problems more difficult, like building an Entity Component System, since the borrow checker doesn’t always play nicely there. But overall, I’m in love with Rust. Unless I’m writing a game engine from scratch again, and even then, I’m not sure I’d want to deviate from Rust.(I’d just build on top of Bevy anyway.)
Dependency management feels so much smoother than it ever felt with C++. I actually enjoy using Cargo more than almost every C++ build system I’ve ever tried. Make files are probably the only thing I liked more, but that’s just because of their simplicity. They don’t handle cross‑platform support the way Cargo can.
I’ve also fallen in love with Rust’s macro system. For almost this reason alone, I never want to write another C‑style macro again. Pulling directly from the static generator’s source:
#[macro_export]
macro_rules! debug {
($($arg:tt)*) => { // The syntax looks a little like a the scurge that is templates in C++, but it's definitely worth it.
#[cfg(debug_assertions)] // Using C macros this would always have to exist, but Rust can remove the whole block in release builds!
{
println!("[DEBUG] {}", format!($($arg)*));
}
};
}
Furthermore, I have fallen absolutely in love with not having to write a dozen header files alongside every C++ file in my source tree. Splitting declarations and definitions across multiple files is surprisingly hard to keep in your head, and it leads to a lot of boilerplate that Rust just doesn’t require.
My many gripes with C++
C++'s many different implementations of a compiler are each somehow objectively one of the worst compilers I have ever used in my life. Half of the messages are so cryptic that the only way I feel I've been able to know what they mean is by already knowing. not to mention the decades of technical dept leading random stray features that no rational language should have in the 21st century, such as undefined behavior due to just not auto setting a value for a variable.
Templates are another nightmare. They’re powerful, sure, but the syntax is awful, the compile times are awful. Every time I touch templates, it feels like I’m writing code in a cursed sub‑language bolted onto C++ as an afterthought.
Not to mention there's about a half a dozen security issues born out of the multiple decades of technical dept. And I know Rust interprets with C, still technical dept. It does hide a lot of it from you unless your writing unsafe code though.
And finally, object oriented programming. I won’t go in depth here, but I’m convinced OPP is one of the worst paradigms we’ve come up with as a species. Brian Will explains it better than I ever could under his why OPP programming is bad video.
Okay so, how does the website compare with Bash for readability?
More of a moot point, considering I never rewrote my static site generator in rust for a technical reason. I haven't actually timed either implementation but they're both about as fast from just an glance, that I honestly do not care.
I will say, the Rust code is far easier to maintain and add more features onto it than the Bash could ever was or could be. Even after going ahead and trying to clean up my code base in bash and properly segmenting it out across multiple files. I really do though suggest a static site generator as a side project for anybody wanting to learn a language or learn shell scripting better. It absolutely was a learning experience at the end of the day. But my no stretch of the imagination do I have any plans to ever maintain the legacy code base or switch back to it. Considering it is honestly terrifying to look at now.
Plus now I can bolt even more features onto my very nice homegrown website! :D I do hope to go ahead and make more posts in the future, as I add more features onto the website, and/or come up with other things to write blogs about.
-- Racclyn