11 ms·
The C++ code I write these days is actually pretty similar to Rust: everything is explicit, lots of strong types, very simple and clear lifetimes (arenas, pools
by thrwyexecbrain 1y ago
The C++ code I write these days is actually pretty similar to Rust: everything is explicit, lots of strong types, very simple and clear lifetimes (arenas, pools), non-owning handles instead of pointers. The only difference in practice is that the build systems are different and that the Rust compiler is more helpful (both in catching bugs and reporting errors). Neither a huge deal if you have a proper build and testing setup and when everybody on your team is pretty experienced.
By the way, using "atoi" in a code snippet in 2025 and complaining that it is "not ideal" is, well, not ideal.
- yodsanklai 1y ago> The C++ code I write these days Meaning you're in a context where you have control on the C++ code you get to write. In my company, lots of people get to update code without strict guidelines. As a result, the code is going to be complex. I'd rather have a simpler and more restrictive language and I'll always favor Rust projects to C++ ones.
- bluGill 1y agoThat is easy to say today, but I guarantee in 30 year Rust will have rough edges too. People always want some new feature and eventually one comes in that cannot be accommodated nicely. Of course it will probably not be as bad as C++, but still it will be complex and people will be looking for a simpler language.
- timbit42 1y agoHow many rough edges will C++ have in another 30 years?
- bluGill 1y agoWho knows. It will likely have more than any other language. Though it will also continue to not get credit for things it got right. There will always remain two types of languages: those that nobody uses and those that everybody complains about.
- leftyspook 1y agoCould it be that it gets no credit for things it got right because it got barely anything right?
- simonask 1y agoRust has rough edges today. The field of programming is still only a few decades old, and there's no doubt that something even shinier will come along, we just don't know yet what that looks like. That's not a good reason to stick with inferior tools now, though.
- bluGill 1y agoWhat does inferior mean? Rust is inferior to C++ for my needs. This is just a reflection on we started a large project in C++ before rust existed, and now have millions of lines. Getting Rust to work with our existing C++ is hard enough as to not be worth it. Rewriting in Rust would cost 1 billion dollars. Thus despite all the problems we have with C++ that Rust would solve, rust is inferior. (Rust is working on their C++ interoperability story and we are making changes that will allow using Rust in the future so I reserve the right to change this story in a few years, but only time will tell)
- simonask 1y agoI don't think it's a defect of the language that your particular circumstance makes it infeasible to port your project. Having a great C++ interop story would be amazing, but Rust would be decidedly less awesome if it had made concessions in that direction early on. There's a lot of warts here, particularly around the fact that all Rust types are "trivially relocatable" in C++ parlance. At the same time, figuring out which C++ types are trivially relocatable is pretty difficult. To give you an idea of the current situation, all or most non-POD C++ types must be "pinned" on the Rust side, forcing you to deal with the rather clunky `Pin<&mut T>` API. Either that or heap-allocating all C++ types owned from Rust code. Not great. The story is likely to improve, hopefully. There's an interesting overview here: https://hackmd.io/@rust-lang-team/rJvv36hq1e https://hackmd.io/@rust-lang-team/rJvv36hq1e
- bluGill 1y agoI didn't say it was a defect. I said it made rust inferior for me. Those are different things. I don't disagree with rust reasons for making that tradeoff - but the tradeoff as a result makes rust useless for now, for me. If it works for you great.
- taylorallred 1y agoCool that you're using areas/pools for lifetimes. Are you also using custom data structures or stl (out of curiosity)?
- thrwyexecbrain 1y agoNothing fancy, I found that one can do almost anything with std::vector, a good enough hash map and a simple hand-rolled intrusive list.
- senderista 1y agostd::vector is the only STL container that makes sense to use in practice.
- kanbankaren 1y agoThe C++ code I wrote 20 years ago also had strong typing and clear lifetimes. Modern C++ has reduced a lot of typing through type inference, but otherwise the language is still strongly typed and essentially the same.
- pjmlp 1y agoUnfortunely thanks to the "code C in C++ crowd", there is this urban myth that goodies like proper encapsulation, stronger types, RAII, were not even available in pre-C++98, aka C++ARM. Meanwhile it was one of the reasons after Turbo Pascal, my next favourite programming language became C++. For me mastering C, after 1992, only became mattered because as professional, that is something that occasionally I have to delve into so better know your tools even if the grip itself has sharp corners, otherwise everytime the option was constrained to either C or C++, I always pick C++.
- simonask 1y agoThe strong/weak distinction is a bit fuzzy, but reasonable people can have the opinion that C++ is, in fact, loosely/weakly typed. There are countless ways to bypass the type system, and there are implicit conversions everywhere. It _is_ statically typed, though, so it falls in a weird category of loosely _and_ statically typed languages.
- int_19h 1y agoI think that explicit casts really ought to be discounted, since if you're writing one, you are simply getting what you have asked for. This would be like saying that e.g. Modula-2 is weakly typed because it has bitcast. That aside, the only remaining footgun in C++ is the implicit numeric conversions. What else did you have in mind?
- simonask 1y agoI mean, the default behavior of single-argument constructors in C++ is implicit conversion. You have to opt into explicit conversions using the `explicit` keyword on constructors and assignment operators. Then you have all the shenanigans around placement-new and vtables. If it isn't downright weak, it's also not particularly strong.
- mountainriver 1y agoI still find it basically impossible to get started with a C++ project. I tried again recently for a proxy I was writing thinking surely things have evolved at this point. Every single package manager couldn’t handle my very basic and very popular dependencies. I mean I tried every single one. This is completely insane to me. Not to mention just figuring out how to build it after that which was a massive headache and an ongoing one. Compared to Rust it’s just night and day. Outside of embedded programming or some special use cases I have literally no idea why anyone would ever write C++. I’m convinced it’s a bunch of masochists
- almostgotcaught 1y ago> Every single package manager couldn’t handle my very basic and very popular dependencies Well there's your problem - no serious project uses one. > I’m convinced it’s a bunch of masochists People use cpp because it's a mature language with mature tooling and an enormous number of mature libraries. Same exact reason anyone uses any language for serious work.
- cratermoon 1y agoHow can you simultaneously call cpp a mature language with mature tooling and acknowledge that there's no working package manager used by any "serious" project?
- almostgotcaught 1y agoDo you people really not realize how completely asinine you sound with these lowbrow comments? I'll give you a hint: did you know that C also has no package manager?
- hlpn 1y ago[flagged]
- adgjlsfhk1 1y agoYeah, and it's also much worse for it. There's a reason everyone in C uses their own linked list implementation and it's not because it's a platonic ideal of perfect software.
- andrepd 1y agoLack of pattern matching and move only types means you physically cannot code in C++ as you would in Rust, even ignoring all the memory safety stuff.