Live data from Hacker News

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

lucisqr.substack.com

91–100 of 110 posts

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

#91
post #87

Earlier quoted context omitted.

C++ programs do not fail 30% of the time though. Safety concerns matter when the program is actively being attacked, the reason libjpeg had these bugs in the first place was that it works just fine in absence of attacks so nobody bothered to find them. It would be nice if by switching to some magic language we've got safety at no cost but it's not the case in the reality.

> we've got safety at no cost No one ever said that safety was zero-cost. The article mentions bounds checks, but gives no measurements. Have they ever measured? Most data I've seen is that bounds checks cost less than 1% in real-world code. I will boldly assert that there has never been a product that couldn't be shipped because that 1% caused them to miss a performance goal. We could get into the weeds and go off o…

> The article mentions bounds checks, but gives no measurements. Have they ever measured?

Related, the prominent Rust community member "Shnatsel" wrote an article [1] about exactly that in January. It's a great look at the problem, and gives some actual data to evaluate with.

[1]: https://shnatsel.medium.com/how-to-avoid-bounds-checks-in-ru...

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

#92
post #87

Earlier quoted context omitted.

> we've got safety at no cost No one ever said that safety was zero-cost. The article mentions bounds checks, but gives no measurements. Have they ever measured? Most data I've seen is that bounds checks cost less than 1% in real-world code. I will boldly assert that there has never been a product that couldn't be shipped because that 1% caused them to miss a performance goal. We could get into the weeds and go off o…

> The article mentions bounds checks, but gives no measurements. Have they ever measured? Related, the prominent Rust community member "Shnatsel" wrote an article [1] about exactly that in January. It's a great look at the problem, and gives some actual data to evaluate with. [1]: https://shnatsel.medium.com/how-to-avoid-bounds-checks-in-ru...

Thanks for the reference. Several of the examples given could benefit from loop versioning and/or iteration space partitioning, i.e. the compiler splitting a loop that it cannot prove is always in-bounds to an in-bounds part and a possibly-out-of-bounds part. The HotSpot C2 compiler does this under some circumstances.

E.g. the simplest case:

    for (i = 0; i 
Becomes:

    var t = some_expr;
    if (t 
This approach will have exactly the same behavior as the original program and run without bounds checks in either case. It will even throw at the right time. The cost is having two copies of the loop and a check up-front. This specific case could be done with one version, and other cases can be done with a different partitioning of the loops.

I feel people are lacking imagination on what an awesome buffet of compiler transforms are available when it is both absolutely required to do bounds checks and absolutely necessary to try to eliminate them everywhere. In practice, many many loops are trivially in bounds, many other loops are cold enough or big enough that the cost of a bounds check isn't much. You don't need to unroll and version every loop in the program. And like I said, for the loops outside of this set, where iterations are not affine or the indexes are irregular, you either live with bounds checks or you go deeper on allowing static assertions to prove accesses are in bounds. That's exactly the cases where you probably want checks anyway.

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

#93
post #87

Earlier quoted context omitted.

> we've got safety at no cost No one ever said that safety was zero-cost. The article mentions bounds checks, but gives no measurements. Have they ever measured? Most data I've seen is that bounds checks cost less than 1% in real-world code. I will boldly assert that there has never been a product that couldn't be shipped because that 1% caused them to miss a performance goal. We could get into the weeds and go off o…

>Have they ever measured? Yes. >Most data I've seen is that bounds checks cost less than 1% in real-world code So? I don't know where you got you data, but the point of the article is that you don't have to pay for the stuff you don't need. Otherwise we could as well use Java or VBA because "most data" says that programs spend 99% of time waiting on IO. If your data shows that then go ahead and use it, other people h…

> the point of the article is that you don't have to pay for the stuff you don't need.

I kind of don't get this attitude, TBH. A bad register allocation decision could cost 5% in the wrong circumstance, yet no one is suggesting reintroducing the register keyword, and rarely do they drop down to asm to get it. But as soon as the cost is for "safety" they're hell-bent on getting rid of it. Wth.

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

#94
post #50

Earlier quoted context omitted.

somewhat OT, but what happened to haskell? a few years ago it was all over HN - now you hardly see any mention of it. surely this won't happen to rust?

Purely my opinion: There was an era of stability in the Haskell project during which it was possible to write code for industrial purposes. A lot of people were attracted to the idea of a memory-safe language that compiled to native binaries, and there wasn't much competition in that area at the time. Then the research-oriented nature of the language and community re-asserted itself with Haskell 2010, and there was a…

I don't think it's got anything to do with Haskell 2010. Haskell is far more widely used in industry today than in 2010 by at least an order of magnitude. Heck, Mercury alone has about 250 Haskell programmers I think. That's probably more industry Haskell programmers than there were at all in 2010.

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

#95
This really reads like someone who's never touched Rust outside of a 15-minute intro or something. The aversion to `unsafe` doesn't really make a whole lot of sense if your main focus is raw performance... that's why there's a big suite of unsafe operations that skip the safety checking steps.

> Although integer underflows and overflows are only checked in debug mode, memory accesses in arrays are constantly checked for bounds unless you’re in unsafe mode, which defeats the purpose.

Which purpose? The idea is that the majority of code that people write is in safe-land, and the bits of unsafe you use are up to you to verify that you've used it correctly. Using `unsafe` doesn't "defeat the purpose" of Rust, it tells Rust to trust that you've done something correctly.

> Well, yes, if you are going to list the “safety” of Rust compared to C++ as a pro...

"Pro" =/= "never makes mistakes". Memory safety is hard. Mistakes happen. C++ will happily crash at runtime while Rust will catch roughly 100% of mistakes in safe code at compile-time. Writing unsafe code yourself is certainly hard, but chances are that the Rust community has already done the hard part for you and made a crate featuring the data structure you're looking for. At that point, there's very few memory-related foot-guns primed for you to shoot yourself with.

> Again, pundits will state that you could have called one of the arithmetic wrapping functions, which will force the compiler to do this optimization. Well you can do many things but here we are measuring the effect of the compiler over two similar blocks of code.

"If you ignore the thing that lets the Rust code do the thing that you want it to, then the Rust code doesn't do the specific thing you want it to."

> C... was created with the use case of it being a low level language... C++ inherit that, which makes it arguably the easiest language to code memory-intensive algorithms and data structures like hash maps, btrees, vectors and lists.

nit: "C++ inherit_s_ that". Also, this just speaks as someone who hasn't been a junior in a very long time. The number of ways you can subtly fuck up memory access in C++ is astounding, so much so that people have spent hundreds of thousands of man-hours designing memory safe languages like... Rust...

> This means that a good developer who knows how to take advantage of cache/locality, will have a good time implementing such algorithms and data structure with C++ and will very likely struggle with Rust for the same task.

Define a "good developer" more specifically. A good Rust developer certainly knows how to handle unsafe code without shaking in their boots.

> Rust mandates the use of its own compiler - rustc - which is a top driver of the LLVM stack, pretty much as clang is for C++. C++ on the other hand, has dozens of good quality compilers available in many platforms.

C++ is a 38 year old language designed in a time when you'd be happy that you had a compiler at all, let alone one that worked properly. Having multiple compilers for a language isn't a necessarily good trait, it just means that more work was spent duplicating functionality. And despite that previous statement, Rust doesn't "mandate" you use any particular compiler; there are multiple projects actively targeting other backends like GCC and cranelift.

> Although the scenario is changing rapidly, the pool of engineers with C++ background is much larger than the pool of Rust developers

See "C++ is a 38 year old language"...

> But safety against what? In many years of coding C++, very rarely I experienced a stack overflow or segmentation fault. It is literally not an issue in every codebase I have worked with.

Are you... sure you're using C++ then? This statement comes across as both a humble-brag and also just patently false if you've done anything even remotely lower-level. Does the author mean to say that he's never before experienced memory mismanagement?

> Are we talking about safety against hackers?

No...? You can just read the second sentence on the Rust websi-

> Or are we talking about protection against crashes?

No seriously it's righ-

> a heavily protected, garbage collected language as C#

Garbage collection doesn't mean your code is sa-

> However segfaults can be caught with a signal trap and handled cleanly like any Java/C# exceptions

Whew, that's probably the worst claim yet. The author legitimately links to an article that mangles the call stack by performing arbitrary code execution during a SIGSEGV handler. And has the audacity to call that being "handled cleanly". Wow.

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

#96

> "Why I think C++ is still a desirable coding platform compared to Rust" And yet, C++ remains an undesirable coding platform, for the reason alone that there is no package manager. It's difficult to take this blog seriously when there is not even a faint mention of Cargo. But even beyond that, I have other gripes with other fundamental points of the author's case: > But is that an apples-to-apples comparison? Well,…

Conan and vcpkg are already quite rich for the libraries that matter.

Other than that, even as C++ aficionado, I agree there is a general resistance against safety in general and Rust in particular.

To the point that while there are compiled managed languages that can also take over some C++ roles, those die hards only see Rust as a threat.

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

#97
post #93

Earlier quoted context omitted.

>Have they ever measured? Yes. >Most data I've seen is that bounds checks cost less than 1% in real-world code So? I don't know where you got you data, but the point of the article is that you don't have to pay for the stuff you don't need. Otherwise we could as well use Java or VBA because "most data" says that programs spend 99% of time waiting on IO. If your data shows that then go ahead and use it, other people h…

> the point of the article is that you don't have to pay for the stuff you don't need. I kind of don't get this attitude, TBH. A bad register allocation decision could cost 5% in the wrong circumstance, yet no one is suggesting reintroducing the register keyword, and rarely do they drop down to asm to get it. But as soon as the cost is for "safety" they're hell-bent on getting rid of it. Wth.

> A bad register allocation decision could cost 5% in the wrong circumstance

5% of what?

>yet no one is suggesting reintroducing the register keyword

If I understood you, you mean that some variable might be allocated on stack instead of register and we need "register" keyword to alleviate this? Not really, when such thing happens we write asm() block which has all capabilities of the old register keyword and much more. And if 5% is latency then who in real time would not get to asm() to get it? This whole talk of "1% this, 5% that" seems just some kind of reddit meme. Would you give me 1% of your income for nothing? If not then why would you increase latency by 1%? Would you write five line of assembly to get 5% raise? If you would, then why would not you want to do it to drop latency by that much?

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

#98

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 e…

there is another key difference between rust and c++, rust by default bundles its stdlib into the executable, which make each executable kind of a static binary, they add up fast. c++ uses shared libraries, smaller in size for the whole system, and, you can upgrade a library separately too. on embedded systems where storage space is restricted, rust is simply a no-go.

Flash storage is getting cheap. There is some places where it matters.... but on everything else.... I am really not a fan of dynamic linking.

Linux has proven for a very long time that if you have 100 programs, and they each have 100 dependencies, you'll probably see an occasional issue related to incompatibility.

It seems like it's suited to the mindset of unique systems maintained by sysadmins, with every app being a part of the system, quite possibly built locally just for your task.

The modern way seems to be disposable installs that cab be recreated automatically if some probably-not-worth-fixing thing happens, made of reusable multipurpose software made by people who have never heard of your application, and a bit of local code, which might be intended to someday become one of those mega-frameworks.

Even windows used to always have hassles with some visual C++ runtime or other.

Although the standard library of C isn't a big issue since it's not in the habit of breaking things, but I'd imagine Rust might want to make bigger changes since it's so new.

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

#99

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 e…

there is another key difference between rust and c++, rust by default bundles its stdlib into the executable, which make each executable kind of a static binary, they add up fast. c++ uses shared libraries, smaller in size for the whole system, and, you can upgrade a library separately too. on embedded systems where storage space is restricted, rust is simply a no-go.

All embedded applications and libraries can be declared with no_std, removing the std dependency and heap allocation.

Shared libraries are also possible.

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

#100
> Resources Available

> Also, the quantity of teaching material and resources available to learn the language is currently overwhelmingly more abundant on the C++ side.

Quality over quantity. I'm a predominantly C and C++ developer, and the generic resources for C and especially C++ are horrible for the better part. This changes though when you look at what actual experts are putting out, either by themselves or by presenting at some convention, etc..., but these resources take knowing where to look, and many of them are useless in the process of learning the essentials, which everybody will screw up, because the language doesn't guide you, unlike Rust, which nannies you a lot (thankfully!!! you understand if you've written enough C++.)

> So if I want to bet safe in the development of a new system, I have to go with C++.

despite what I said above, C++ is prone to getting you in very unique scenarios if you're actually doing a new system (my anecdote), so you can't rely on people who aren't already skillful to even figure out that there's issues, even less how to address them. There's no guidance, really (unless you use C++Insights and hack stuff to compile-time.)

> In many years of coding C++, very rarely I experienced a stack overflow or segmentation fault. It is literally not an issue in every codebase I have worked with.

You espouse a pop understanding of software issues. These issues are not just magic, they happen for very exact reasons, this is why we can work against them happening in the first place.

I end my comment with saying that I'm not even a big fan of Rust, it's very specifically designed, I do not like the principles that Rust builds on, but I still disagree with your analysis.

Post reply on HN