3 ms·
> Coding modern C++ right is the same, that way, as coding Rust: when it compiles, it works. Works in what way? Serious question. Do you mean "works" as in 1)
by kortex 5y ago
> Coding modern C++ right is the same, that way, as coding Rust: when it compiles, it works.
Works in what way? Serious question. Do you mean "works" as in 1) "doesn't crash/seg/overflow" or 2) "doesn't UB" or 3) "doesn't have race bugs" or 4) "does what the programmer intended"?
I would say from my experience, none are strictly true. I'll hazard you mean to imply the dev knows the language pretty well in order to satisfy "works lvl 1" but you still have veterans running into bugs of the 2-4 variety.
But even to get to (1), C++ requires a ton of domain knowledge. I've been working with C++ intensively for several months and incidentally for years, and I still seg every now and then. Even after using Valgrind, it feels rickety. Meanwhile, I've spent a few dozen weekends on Rust and I just feel way more confidence that my program will "just work" without crashing.
That's all still "level 1 works". When it comes to race conditions and programmer intent making its way into correct code, it's no comparison. Rust is way easier to get my intent into a running program. C++, I still have to lean into logs and debugging, because it just doesn't quite do what I want a non-trivial amount of the time.
It's not a religion. Rust simply is a better experience. I can say that having learned both basically side-by-side.
- ncmncm 5y agoWorks as (4), does what I intended. It takes discipline to learn to write C++ in the modern way. It is work to keep up with improvements in the language and library, as new Standards are published. But many, many professionals do. C++ is not a toy. It has sharp edges that must be treated with respect. But if you do make the effort to keep up, and lean hard on the type system to help everywhere it can, the language delivers. If your code feels rickety, it is. You have at hand the tools to fix that. If you find yourself coding races, it is because you have not adopted means to prevent them. I can testify that coding in modern C++ can be pure fun. I never have occasion to worry about memory safety, or data races. Code not working the way (I thought) I wanted, on first run, is very much the exception.
- shakow 5y ago> It takes discipline to learn to write C++ in the modern way. It is work to keep up with improvements in the language and library, as new Standards are published. But many, many professionals do. C++ is not a toy. It has sharp edges that must be treated with respect. But if you do make the effort to keep up, and lean hard on the type system to help everywhere it can, the language delivers. If it is such a core just to hope to, one day, be able to code that, maybe, won't crash, what do you think is the point of using C++ over Rust?
- ncmncm 5y agoC++ doesn't need a point. C++ is a mature language with mature tooling, an installed base of tens or hundreds of billions of lines of code, millions of professionals worldwide getting critical work done every day, with guaranteed prospects decades into the future. You personally depend on C++ code not crashing hundreds or thousands of times every day, without knowing it. In some possible futures, Rust code may take up just a bit of the load. The most value would come from its displacing C and Java in new projects.
- kaslai 5y agoI depend on a mountain of C and C++ code to not only not crash, but to also not have any subtle memory errors which might allow a packet from the internet to run arbitrary code on my machines. Failures of that sort are disturbingly common.
- ncmncm 5y agoYou stand to gain more by people modernizing their existing code -- even, compiling their C code with a C++ compiler, and then improving that, as happened with excellent results in gcc and gdb -- than by hoping a vanishing few will switch over to a wholly new, unfamiliar language. Liiterally millions of times more benefit.