Live data from Hacker News

Modern C++ Won't Save Us

alexgaynor.net

61–70 of 395 posts

Re: Modern C++ Won't Save Us

#61
post #55
post #13

Earlier quoted context omitted.

The thing is, Rust has tools that are easier to use _and_ have great performance _and_ prevent security and stability mistakes.

Does rust have a structure to handle something like a stringview?

Yes, a borrowed string slice `&str`, whose lifetime is tracked precisely by the compiler to avoid use-after-free errors. https://doc.rust-lang.org/book/ch04-03-slices.html#string-sl...

Re: Modern C++ Won't Save Us

#62
post #13

Earlier quoted context omitted.

The thing is, Rust has tools that are easier to use _and_ have great performance _and_ prevent security and stability mistakes.

However Rust is single vendor and single implementation, has a much smaller community and ecosystem than C++, is not standardized, and does not support all of the platforms and use cases that C++ does.

All of those problems are long-term solved by using more Rust, whereas none of C++'s problems are long-term solved by using more C++.

(Personally, I don't find single-vendor or lack of standardization a problem in practice, and I've never written C++ for a platform Rust doesn't support.)

Re: Modern C++ Won't Save Us

#63
post #58
post #53

Earlier quoted context omitted.

While there are obviously still cases where C++ makes sense to use today, those case are overwhelmingly based on the age and maturity of the C++ ecosystem. Now that Rust has proven that a language can provide memory safety without compromising (much) on performance, it is clear that the scope of C++'s supremacy is in permanent decline. As Rust (or another language with similar safety/performance properties) matures a…

> In other words: C++ is the new Fortran. Which makes Rust the new... APL? I think the analogy is pretty apt as far as it goes. Fortran by the 70's was a crufty language with a bunch of legacy mistakes that remained very popular and very useful and would continue to see active use for decades to come. And everyone knew that. And everyone had their own idea about the great new language that was "clearly" going to repl…

It’s definitely easier to reason about than C++ because it errs on the side of safety and explicitness. You can use things you don’t understand without fear which straddles the boundary in a good way IMO. To your point that doesn’t make it simple.

As a work-a-day hacker it’s completely become my go to language when I’m writing tools, libraries or just want to knock out a simple algorithm to prove myself right or wrong.

Re: Modern C++ Won't Save Us

#64
post #58

Earlier quoted context omitted.

> In other words: C++ is the new Fortran. Which makes Rust the new... APL? I think the analogy is pretty apt as far as it goes. Fortran by the 70's was a crufty language with a bunch of legacy mistakes that remained very popular and very useful and would continue to see active use for decades to come. And everyone knew that. And everyone had their own idea about the great new language that was "clearly" going to repl…

It’s definitely easier to reason about than C++ because it errs on the side of safety and explicitness. You can use things you don’t understand without fear which straddles the boundary in a good way IMO. To your point that doesn’t make it simple. As a work-a-day hacker it’s completely become my go to language when I’m writing tools, libraries or just want to knock out a simple algorithm to prove myself right or wron…

> It’s definitely easier to reason about than C++

See... I don't think that's true, and argue the huge body of C++ code and talent in the ecosystem is an existence proof to the contrary.

I mean, sure, C++ has its crazy edge cases and its odd notions. But you don't need to understand the vagaries of undefined behavior, or the RVO, or move semantics to write and deploy perfectly sensible code. Literally hundreds of thousands of people are doing this every day.

Now, that may not be a convincing argument about the value of that code. But it's absolutely an argument about the utility of the language in aggregate.

I'll be frank: probably 40% of professional C++ programmers aren't going to be able to pick up Rust and be productive in it, at all. And at the end of the day a language for The Elite isn't really going to mean much. We've had plenty of those. Rust is the new APL, like I said.

Re: Modern C++ Won't Save Us

#65
post #11

From the article: > Dereferencing a nullptr gives a segfault (which is not a security issue, except in older kernels). I know a lot of people make that assumption, and compilers used to work that way pretty reliably, but I'm pretty confident it's not true. With undefined behavior, anything is possible.

Linux hit a related situation: a harmless null pointer dereference was treated by GCC as a signal that a subsequent isnull test could not be true, causing the test to be optimized away. https://lwn.net/Articles/575563/

My opinion on that, is that such code MUST NOT be optimized away. Instead it should be a compile error.

Re: Modern C++ Won't Save Us

#66
post #22
post #15

Question - How does one write microcontroller code (or other memory-mapped I/O code) using a memory-safe language?

Historically speaking, you didn't. It is only relatively recently that microcontrollers have become powerful and spacious enough for that to be an option.

I remember a time when folks sighed wistfully at the idea of being able to afford wasting cycles and memory on C in embedded...

Re: Modern C++ Won't Save Us

#67
post #12

Rust and Swift have different definitions of memory safety, don't they?

Yes, AIUI Swift does not ensure memory safety for concurrent code like Rust does. You have to expressly opt-in to concurrency-safety, and it's not checked by the compiler. Go definitely has this issue, which is admittedly bizarre for a language that's so often used to code network-oriented services making heavy use of concurrency.

That's because Swift doesn't have a first-class concurrency story yet. I imagine that concurrency safety will be sorted out when Swift gets concurrency, but in the meantime all Swift concurrency is using C primitives like pthreads and libdispatch.

Re: Modern C++ Won't Save Us

#68
post #64

Earlier quoted context omitted.

It’s definitely easier to reason about than C++ because it errs on the side of safety and explicitness. You can use things you don’t understand without fear which straddles the boundary in a good way IMO. To your point that doesn’t make it simple. As a work-a-day hacker it’s completely become my go to language when I’m writing tools, libraries or just want to knock out a simple algorithm to prove myself right or wron…

> It’s definitely easier to reason about than C++ See... I don't think that's true, and argue the huge body of C++ code and talent in the ecosystem is an existence proof to the contrary. I mean, sure, C++ has its crazy edge cases and its odd notions. But you don't need to understand the vagaries of undefined behavior, or the RVO, or move semantics to write and deploy perfectly sensible code. Literally hundreds of tho…

I'm curious, what has given you the impression that Rust is a language "for the elite"? It certainly has some rough edges around learnability, but I don't think anyone is actively trying to discourage people from picking it up. Rust is certainly hard for experienced programmers because some common patterns in other languages are not allowed by Rust's rules, but that's no different than trying to apply OOP in a functional language.

Re: Modern C++ Won't Save Us

#69

Earlier quoted context omitted.

However Rust is single vendor and single implementation, has a much smaller community and ecosystem than C++, is not standardized, and does not support all of the platforms and use cases that C++ does.

Fair points, but none of them are inherent to the language itself.

The thing is....people don't run "the language itself".

Re: Modern C++ Won't Save Us

#70
post #23

Earlier quoted context omitted.

That’s very true. But all of those communities, ecosystems, standards, and use cases have an extreme learning curve and a very deep problem with security. :-)

Rust's learning curve isn't exactly a shallow one either. For the record I think Rust has a lot going for it, but it is not the C++ killer that many are touting it to be.

C++ has a huge learning curve too though, the difference is it lets you write whatever you want. The learning curve is to write correct C++. It’s deceptive, it’s like skiing vs snowboarding. Skiing you pick up fast but to get good is damn hard and few bother. Snowboarding is damn hard to pick up but then it’s pretty easy to become really good.
Post reply on HN