4 ms·
I agree. I'm using it both in the game server, the client and for scripting! So far I haven't really had any serious problems that would be related to unsafety.
by fwsgonzo 3y ago
I agree. I'm using it both in the game server, the client and for scripting! So far I haven't really had any serious problems that would be related to unsafety. You just have to be disciplined. Source: https://medium.com/@fwsgonzo/using-c-as-a-scripting-language-part-9-afd4e32dfb72 https://medium.com/@fwsgonzo/using-c-as-a-scripting-language...
I do see that peoples experience with C++ varies wildly, because shops either don't understand why modern C++ exists or they don't care. Either way, predictably, their software suffers and they will routinely run into segfaults. C++ obviously isn't perfect. It's an old language, and while it's trying to reinvent itself it will take some time.
If you ask me though, I don't give a rats ass about the safety things. My $dayjob is a big infrastructure product written in C, which practically never crashes because of memory problems. It just doesn't happen because of extreme discipline. Asserts when entering. Asserts when leaving. Magic values in structs. Sanitizers, clang-tidy, coverage, custom test frameworks, fuzzing. We have it all. And it's C! I understand newbies do better with Rust than C++. It makes a lot of sense. Still, I think that people use Rust more because it's easy to add dependencies, because it has 1 (one) build system, and because of that it's easy to build larger projects because of this. CMake has made good strides recently, but it needs to become the build system for C and C++, and we need global repositories to match Rust. Will that ever happen?
- typedef_struct 3y agoIf openssl and skia would switch [to cmake], we'd be on our way.
- fwsgonzo 3y agoThere is this one: https://github.com/janbar/openssl-cmake https://github.com/janbar/openssl-cmake but I mostly use it to embed OpenSSL.
- BanTheBastards 3y agoSpeak for yourself: I'm not returning to the world of "discipline" (aka lost productivity) without a damn good reason to carry on existing codebases. It's just a waste of a good coder and certainly of good time.
- Jyaif 3y agoIn C++ discipline is optional. In Rust it's mandatory.
- timw4mail 3y agoIn C++ crashing with a helpful error is rare. In Rust it's rare not to get a helpful error.
- BanTheBastards 3y agoI completely disagree; discipline is only optional in C++ if you want to ship broken code. Even the top poster in this thread that actually cops to the productivity overhead of C++ admits (albeit obliquely) they still make memory errors
- steveklabnik 3y agoI think this is amusing because both directions completely work: In C++, you can do whatever. Rust forces you do to some things. No discipline required by C++, absolutely required by Rust. In C++, you can do whatever. Rust forces you to do some things. This means you must have discipline in C++, or you will do bad things. But in Rust, you can do whatever you want, the compiler has your back.
- Jyaif 3y agoGood point, I was imprecise. I should have said that no discipline is required in C++ to obtain a binary.
- jackmott42 3y agoEven brilliant developers on the Linux kernel teams and Postgres teams make memory mistakes that lead to security problems. Maybe you are at a higher level than them though.
- fwsgonzo 3y agoMy point is that I am acknowledging that C and C++ needs more discipline. I'm not saying we eliminated this class of bugs!
- mrcsd 3y agoIt sounds like you're working on a mature C++ codebase, so yeah, good reason to stick with that. But I'm curious whether you feel it's worth spending effort on this discipline, outside of working on a particular codebase? I don't know C++, but being freed from making effort to avoid a class of bugs was easily enough for me to learn Rust instead (not that this was the only reason).
- fwsgonzo 3y agoI think if I had the opportunity to learn Rust, and some guidance so that I didn't have to do everything the hard way (essentially how I learned C and then C++), then I would! So far I have used Rust very little, but what I have seen I have liked. I especially liked the much simpler inline assembly in Rust.
- Yoric 3y agoThat's a lot of boilerplate code, scaffolding and additional instrumentation. In fact, much of my experience with C++ is at Mozilla, which does all of that and more. And still needs a team dedicated to recording and investigating crashes. That's the reason for which Mozilla (and now some of the developments at Google, Facebook, Microsoft, Amazon) has started moving to Rust a while ago. Also, I've written it somewhere else, but I'm going to repeat it: > which practically never crashes because of memory problems When you have memory issues, crashes are the lucky case. The common case is random memory corruption.