Live data from Hacker News

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

lucisqr.substack.com

11–20 of 110 posts

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

#12
post #7

A few things I've found notoriously difficult to do in C++: 1. Add two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit integers. If the sum is going to overflow, generate an error. If the sum is not going to overflow, evaluate the sum. 2. Multiply two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit in…

I'm pretty sure a good math library makes this problem easy to be solved. Not sure you need a new language.

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

#13
post #7

A few things I've found notoriously difficult to do in C++: 1. Add two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit integers. If the sum is going to overflow, generate an error. If the sum is not going to overflow, evaluate the sum. 2. Multiply two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit in…

Yes.

https://doc.rust-lang.org/std/primitive.i64.html#method.chec...

https://doc.rust-lang.org/std/primitive.i64.html#method.chec...

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

#14
post #7

A few things I've found notoriously difficult to do in C++: 1. Add two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit integers. If the sum is going to overflow, generate an error. If the sum is not going to overflow, evaluate the sum. 2. Multiply two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit in…

If you use MSVC maybe it's more of an issue, but on GCC and Clang we have __builtin_overflow_*. There are many variants: https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins...

I use them all the time.

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

#15
post #7

A few things I've found notoriously difficult to do in C++: 1. Add two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit integers. If the sum is going to overflow, generate an error. If the sum is not going to overflow, evaluate the sum. 2. Multiply two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit in…

Rust has i64::checked_add and i64::checked_mul, which return None on an overflow. Not only is it easy to do, the compiler help ensure you checked the result.

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

#16
post #7

A few things I've found notoriously difficult to do in C++: 1. Add two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit integers. If the sum is going to overflow, generate an error. If the sum is not going to overflow, evaluate the sum. 2. Multiply two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit in…

If you use MSVC maybe it's more of an issue, but on GCC and Clang we have __builtin_overflow_*. There are many variants: https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins... I use them all the time.

When you have wrappers over these that produce optional types, and use statement expression macros or monadic member functions to handle the control flow, I think it's not too hard.

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

#17

> the pool of engineers with C++ background is much larger than the pool of Rust developers Well that's pointless.

I'd wager that any highly qualified C++ engineer worth working with can pick up Rust and become a highly qualified Rust engineer in And honestly, I'd rather work with those people than with people who came to Rust from languages like Python, Java, TypeScript, etc.

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

#18
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.

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

#19
post #7

A few things I've found notoriously difficult to do in C++: 1. Add two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit integers. If the sum is going to overflow, generate an error. If the sum is not going to overflow, evaluate the sum. 2. Multiply two signed 64-bit integers without overflowing on either side (negative or positive) and without using 128-bit in…

  > Does Rust make this kind of problems easy to be solved?
For this specific case (specified behavior on overflow), Rust makes it trivial. All of the primitive integer types have methods such as `checked_mul()` or `saturating_add()`, which provide deterministic arithmetic on all platforms.

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

#20

all my new projects are in c17 and c++20,no rust for me. I agree they need a build system like cargo, though cmake kind of works for me. with carbon and cppfront in the works,c++ will keep evolving

I actually think Cargo & crates.io are the weakest and shittiest part of Rust right now. They're a bit amateur.

But yes, CMake is something I do not miss. Though I miss the alternatives even less. Though C++ with Bazel is actually quite attractive.

Post reply on HN