3 ms·
Unsolicited opinion: I've been writing C++ for many years, leading a large open source project, writing lots of different code in different domains (embedded, m
by lionkor 2y ago
Unsolicited opinion: I've been writing C++ for many years, leading a large open source project, writing lots of different code in different domains (embedded, multi-threaded game servers, games, cross platform games, toy kernel(s), website backends, toy databases, a lot of interpreters, compilers, and other such things, parsers). I'm happy to use any and all newer features. I never got into coroutines, but other than that, I find boost's code to be "not so bad". I have similar experience with C alongside that.
I wrote some small games in Zig, I made some money writing Go. I dabbled in Elixir, Erlang, some Lisps, it goes on. I love programming. After my 9-5 C# Job nowadays I usually spend a few hours programming with my friends.
I was extremely skeptical of Rust, due to the hype and some very obnoxious Rust proponents. I learned Rust, I'm still learning it, but I've shipped a few smaller backend apps and worked on a few larger projects now.
The main reason why I think that Rust should replace C++ in all new projects is actually very simple: Tagged unions, pattern matching, reflection, no OOP and the toolchain.
There is a lot of syntax in Rust that is beautiful, but besides that, those are the most useful features. They save hundreds to thousands of lines of code per codebase, compared to C++. The Option<T> alone is a simple
enum Option<T> {
Some(T),
None,
}
Whereas in C++, std::optional<T> is a massive class with edge cases, weird implicit conversions ({} = std::nullopt, beware), and don't even start with differences between different STL implementations. What about `std::make_optional`? At least C++23 adds monadic operations like `.and_then()`, but with the "let's capture by reference why not" lambdas in C++, you easily have dangling references in your lambdas if you do anything multithreaded.
In Rust, I just write code, and if it compiles, it runs and does *exactly* what it says. I don't have to run the code to see if it crashes just because I'm using multiple threads, or a bunch of tokio async tasks. In C++, sure, if it compiles you cleared the first hurdle, but about 60% of the time the code has edge cases you're not considering. Most if not all C++ code I've seen makes assumptions about the lifetimes of things, and/or uses globals, and/or happily uses shared pointers in ways that they were not designed. Anything using `boost::asio` is a gigantic clusterfuck of "make sure you pass by value, by rvalue reference, or as a shared pointer" that, of course, not a single linter or compiler will tell you about if you don't. They don't have to tell you, because that's UB, and that probably crashes horribly, but maybe not!
I can't wait for more people to use Rust so their ecosystem matures a little more.
- lionkor 2y agoTo add: The only people I know who think C++ is easy to write "good" code for, and who think that you can "just" be careful and skilled, have NEVER written multithreaded server code in C++. Hit a multithreaded C++ server with 20k users a day alone and you would not believe the edge cases and weird states they will generate for you.
- leni536 2y agoLambda captures are explicit in C++, so if you dislike capturing by reference then just don't.
- pdimitar 2y agoI am glad that you have changed your mind. Not because I am a Rust advocate (haven't worked with the language in at least a year now, what advocate would that make me?) but because this: > I was extremely skeptical of Rust, due to the hype and some very obnoxious Rust proponents. ...is obviously a very biased way of gauging anything. As mentioned upthread in another comment of mine, every single community has the minority of loud bad apples and it's not fair to judge Rust because its community is literally like any other on this planet. You did the right thing, you ignored the emotional responses and went to check for yourself, factually and objectively. I'd be honored to call you my colleague. Bravo.
- lionkor 2y agoIt wasn't easy, and I was quite toxic towards Rust posts before that - simply because everything at the time was saturated with Rust news, and a lot of very silly "rewrite it in Rust" posts. There are only three things that annoyed me this much in the last 10 years: Crypto (which was largely a hype-bubble), Rust (which turned out to be very cool), and AI (we'll see where that goes). > You did the right thing, you ignored the emotional responses and went to check for yourself, factually and objectively. I'm currently talking to lots of other C and C++ developers I know, and trying to convince them to give it an honest shot. The first thing I say is pretty much "Hey, I know this thing is overhyped and you're probably fed up, I thought so, too, but ...", and then follow that up with tagged unions, pattern matching and showing the toolchain. That sells most of them on it. Error handling also is a huge plus if they're also big error-handling nerds. Also note how I never mention memory safety -- the reality is barely anyone gets really excited about that. We'd all use @safe Dlang[0] if it was that exciting to us all. [0]: https://dlang.org/spec/memory-safe-d.html https://dlang.org/spec/memory-safe-d.html