Live data from Hacker News

I think C++ is still a desirable coding platform compared to Rust

lucisqr.substack.com

31–40 of 110 posts

Re: I think C++ is still a desirable coding platform compared to Rust

#31
post #4

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... 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, predi…

Even 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.

My point is that I am acknowledging that C and C++ needs more discipline. I'm not saying we eliminated this class of bugs!

Re: I think C++ is still a desirable coding platform compared to Rust

#32
Being able to manage memory manually for certain performance-critical tasks is certainly reason enough that these types of languages will continue to exist.

But the idea that stack overflows are not an issue if you try hard enough and pay attention is not very persuasive. It doesn't take much imagination to see that this principle will falter more and more the larger a project gets and the longer it runs. This remains THE big selling point of Rust to my mind.

Re: I think C++ is still a desirable coding platform compared to Rust

#33
post #4

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... 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, predi…

Speak 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.

In C++ discipline is optional. In Rust it's mandatory.

Re: I think C++ is still a desirable coding platform compared to Rust

#35
Yeah, that's a no from me. I'm a full time C++ dev and every time I code in Rust it is harder for me to switch back. The author has pointed to some issues regarding performance. In the end, you can always rewrite your code to generate other/better assembly, if you really need the speed. I would argue Rust is so much more that just Rust itself. Like many others after noted, it is not only the language, but the whole ecosystem and oh boy is cargo a joy to use. Yes, CMake works ok with vcpkg, but good luck integrating something that is not CMake. Code style, build script/system and different bugs from different compilers do not make my life easier. In addition, we still have old features we cannot repair because of ABI. It is an endless mess.

Re: I think C++ is still a desirable coding platform compared to Rust

#36
post #3

I've done some C++ but no Rust. I'd like to learn a few things from people who have done both. 1. How many years of C++ programming do you have under your belt? How many years of Rust? 2. For new work projects, do you choose C++ or Rust? Why? 3. For new hobby projects, do you choose C++ or Rust? Why? 4. Is there something about C++ that you wish Rust had? 5. Is there something nice about Rust (apart from the borrow c…

> 1. How many years of C++ programming do you have under your belt? How many years of Rust?

12-15 years of C++, 8 years of Rust. I generally used C++ because it was the only tool that could do the job at the time, not because I actually liked it. At best, I had a love/hate relationship with C++.

> 2. For new work projects, do you choose C++ or Rust? Why?

Almost always Rust. The main reasons:

- Cargo is awesome, and the crate ecosystem is incredible.

- I barely trust myself to write rigorously correct C++, despite having plenty of C++ experience and being extremely paranoid about code correctness. And I defintely don't trust most other people to do it correctly. (I have maintained more than my fair share of other people's C++ code, and the average C++ code is buggy garbage.) C++ is like fishing around in a drawer of extremely sharp knives in a dark kitchen; you're going to get cut.

- I trust the average Python or TypeScript developer either to write correct Rust, or to be defeated by the borrow checker. This isn't just the borrow checker—it's also bounds checking on arrays and slices, the choice to panic instead of corrupting memory, the rareness of undefined behavior (and "nasal demons", and irresponsibly aggressive optimizations) in safe Rust, the safe mulithreading support, etc.

However, I would consider using C++ in domains where correctness and security weren't important, and where I wanted to use mature frameworks. Games would be an obvious case!

> 3. For new hobby projects, do you choose C++ or Rust? Why?

Rust. Way more fun, personally. :-) I tend to like using "functional" architectures, so I don't fight the borrow checker much.

> 4. Is there something about C++ that you wish Rust had?

Well, now that const generics are in, I'm pretty happy with Rust's feature set. But for quite a while that was the best C++ feature Rust was missing.

Re: I think C++ is still a desirable coding platform compared to Rust

#37
There's a safe and sane language subset struggling to get out of "modern C++". The essence is following the Rule of 3/5/0, adopting value semantics, explicit ownership via unique_ptr/shared_ptr, resources wrapped as RAII objects. The syntax and feature space is certainly crowded and abused, but playing with the borrow-checker is an entirely different game.

Re: I think C++ is still a desirable coding platform compared to Rust

#38
post #3

I've done some C++ but no Rust. I'd like to learn a few things from people who have done both. 1. How many years of C++ programming do you have under your belt? How many years of Rust? 2. For new work projects, do you choose C++ or Rust? Why? 3. For new hobby projects, do you choose C++ or Rust? Why? 4. Is there something about C++ that you wish Rust had? 5. Is there something nice about Rust (apart from the borrow c…

1. About 15 years of experience in C++, 2-3 years in Rust.

2. I'm retired now, but I would have considered Rust for any greenfield project that didn't have a compelling reason to pick C++ (e.g. mandatory interop with an existing big C++ library).

3. Rust nearly every time. I sometimes use a layer of C++ as an FFI shim, such as when writing a gRPC client/server (the Rust libs there aren't mature).

4. The library ecosystem. Rust's crates.io seems full, but if you scratch the surface it's just a bunch of half-baked hobby projects at v0.x versions. And Cargo (the most popular build system for Rust) has essentially no support for multi-library packages, so instead of something like GLib (a single dep with lots of functionality) it's common to see even trivial programs depending on dozens or hundreds of half-baked hobby projects at v0.x versions.

5. Most of the Haskell/ML-ish functionality, such as traits and proper enums. I'm currently in the middle of a Rust project that's gotten much bigger than I expected (parsers are hard! compilers are hard! zero-copy is hard!), but it's still possible to make progress by leaning heavily on the type system.

I often describe Rust as "a dialect of C++ where the compiler forces Google Standard C++ on the world", or alternatively "the language you'd get if you hired a team of Haskell developers to write firmware".

Re: I think C++ is still a desirable coding platform compared to Rust

#39
> Are we talking about safety against hackers? The large majority of C++ applications are non-public facing.

That is like saying that most screws aren't load bearing, so it's fine if they fail 30% of the time. The way engineering works is that people build on reusable pieces. For example, several bugs in libjpeg have caused serious vulnerabilities in many applications, including web browsers. You cannot predict how software will be used; it will end up somewhere in someone's stack and suddenly its bugs are CVEs with huge impact.

Re: I think C++ is still a desirable coding platform compared to Rust

#40
As a Rust developer (and former C++ developer), I agree with much of what the author writes. I feel that Rust is a largely better language for my tasks but yes, Rust doesn't yet cover all the use cases for C++. I feel that the reasons to pick C++ for any new development are dwindling, but they still exist.

However, this author, like many, does not understand what safety means.

1. There is much more to safety than memory-safety. Safety is about protecting your invariants. A program that is not safe is a program in which things that happen that are contrary to the intent of the developer.

2. Memory-safety is just one of the many tools in the safety toolbox. Without memory-safety, it's really easy to shoot yourself in the foot. With memory-safety, it's still possible, but you have to work harder at it.

3. Segmentation faults or stack overflows are what happens if you break memory-safety and you are extremely lucky. In most cases, what you get is random memory corruption. Do you really want memory corruption in a trading platform?

4. Security and safety are related, but they are different topics. See https://yoric.github.io/post/safety-and-security/ (self-promotion).

Post reply on HN