3 ms·
I tend to think carefully about lifetimes, resource ownership and writing secure code. I am careful with threading, use language idioms to enforce safety and al
by blub 10y ago
I tend to think carefully about lifetimes, resource ownership and writing secure code. I am careful with threading, use language idioms to enforce safety and also use tools (such as valgrind, but also static analysis) to check the code.
This is not as reliable as Rust's compile-time safety checks, but in practice it works well enough for me.
I don't think this is typical for all C++ projects or programmers e.g. I am not particularly impressed by the (little) Firefox code I've seen.
I hope C++ continues to evolve safety features and get closer to Rust's guarantees. I don't think automotive or aviation will switch too soon.
- Yoric 10y agoOut of curiosity, do you have (open-source) examples of C++ projects that do it right? In my numerous-though-irregular years as a C++ programmers, I haven't seen any project producing code that's convincingly safe. I won't list all the pitfalls of C++ here, but, well, who doesn't have war stories of bugs-because-of-aliasing, bugs-because-of-const-doesn't-actually-mean-constant, bugs-because-pointer-is-still-being-used-after-its-mutex-has-been-released, bugs-because-collection-has-somehow-been-mutated-during-traversal, etc? I have reached the point where I feel I can't trust any non-trivial C++ code, so I gladly switched to Rust for all my new non-webdev projects. But back to the question, I would be really happy to see convincingly safe C++ subsets in action. I certainly hope that this would improve my life as a C++ developer, at least for future projects. As a side question, I wonder how many C++ developers actually produce such code.
- blub 10y agoDon't have a link to such a project, I didn't really look. I am seriously considering starting one though, perhaps it's necessary.
- Yoric 10y agoI am genuinely interested. Also, I just realized that doing this right might require dropping lots of legacy C++ code, more or less as would starting in Rust.
- babyrainbow 10y ago>I tend to think carefully.. What about a team? If you are leading a team of programmers, would you rather use Rust (where finding if the code is doing anything unsafe using a simple grep) or C++ where finding dangerous code is a lot harder? I think the point of using langauges like Rust and Haskell only comes into play when the development is done by a team. It is one thing to hope that every one in your team is as disciplined as yourself (including yourself on a bad day), and knowing for certain that the language won't allow bad stuff to happen...
- blub 10y agoDepends on the team. If they're not experienced writing safe C++, I'd go with a safer language (e.g. Java) or teach them if that's not possible. But this also depends a lot on the project, usually it's the case that C++ is the only option available. We can't start using any languages we want, we have to consider industry standards, resource availability and other constraints.