Live data from Hacker News

Matt Godbolt sold me on Rust by showing me C++

collabora.com

591–600 of 675 posts

Re: Matt Godbolt sold me on Rust by showing me C++

#591

Earlier quoted context omitted.

> because it's so obviously a bad idea. Agreed. The history here is compatibility with C type conversion. I just expected a more compelling Rust /C++ comparison but we got an emphasis of a poorly designed feature which the standard has taken steps to improve already.

No, implicit conversion is a deliberate C++ feature and no analog existed in C. Like a lot of awful things about C++ this is their own choice and it's frustrating that they try to blame C for their choices. In C++ when we define a class Foo (a thing which doesn't exist in C) and we write a constructor Foo(Bar x) (which doesn't exist in C) which takes a single parameter [in this case a Bar named x], that is implicitly…

My copy of K&R disagrees with you that implicit conversion didn’t exist in C. See section 2.7 “Type conversions”.

   “Implicit arithmetic conversions work much as expected. In general, if an operator like + or * that takes two operands (a binary operator) has operands of different types, the ``lower'' typekis promoted to the ``higher'' type before the operation proceeds.”
It goes on including giving a table of all the conversions and a set of heuristics which normally apply.

Re: Matt Godbolt sold me on Rust by showing me C++

#592
post #556

Earlier quoted context omitted.

Is there a safety advantage to using Java given that the HotSpot JVM is written in C++? All safe code is built on a foundation of unsafe code.

Sure, but the point is that you can also build reasonably safe abstractions in C / C++.

The last fifty years have shown us that you can't — at least not sustainably and at scale. You can do so at one moment in time, or for smaller projects, but not in the face of large scale projects with team members changing over time.

Re: Matt Godbolt sold me on Rust by showing me C++

#593

This is actually the point where Rust starts to frustrate me a little bit. Not because Rust is doing anything wrong here, but because the first well-known language to really get some of these things right also happens to be a fairly low-level systems language with manual memory management. A lot of my colleagues seem to primarily be falling in love with Rust because it's doing a good job at some basic things that hav…

I suggest taking a look at Gleam. It's a fairly new language but it's gaining traction.

https://gleam.run/

Re: Matt Godbolt sold me on Rust by showing me C++

#594

Earlier quoted context omitted.

Rust has rough edges today. The field of programming is still only a few decades old, and there's no doubt that something even shinier will come along, we just don't know yet what that looks like. That's not a good reason to stick with inferior tools now, though.

What does inferior mean? Rust is inferior to C++ for my needs. This is just a reflection on we started a large project in C++ before rust existed, and now have millions of lines. Getting Rust to work with our existing C++ is hard enough as to not be worth it. Rewriting in Rust would cost 1 billion dollars. Thus despite all the problems we have with C++ that Rust would solve, rust is inferior. (Rust is working on thei…

I don't think it's a defect of the language that your particular circumstance makes it infeasible to port your project. Having a great C++ interop story would be amazing, but Rust would be decidedly less awesome if it had made concessions in that direction early on.

There's a lot of warts here, particularly around the fact that all Rust types are "trivially relocatable" in C++ parlance. At the same time, figuring out which C++ types are trivially relocatable is pretty difficult. To give you an idea of the current situation, all or most non-POD C++ types must be "pinned" on the Rust side, forcing you to deal with the rather clunky `Pin` API. Either that or heap-allocating all C++ types owned from Rust code. Not great.

The story is likely to improve, hopefully. There's an interesting overview here: https://hackmd.io/@rust-lang-team/rJvv36hq1e

Re: Matt Godbolt sold me on Rust by showing me C++

#595

Earlier quoted context omitted.

The strong/weak distinction is a bit fuzzy, but reasonable people can have the opinion that C++ is, in fact, loosely/weakly typed. There are countless ways to bypass the type system, and there are implicit conversions everywhere. It _is_ statically typed, though, so it falls in a weird category of loosely _and_ statically typed languages.

I think that explicit casts really ought to be discounted, since if you're writing one, you are simply getting what you have asked for. This would be like saying that e.g. Modula-2 is weakly typed because it has bitcast. That aside, the only remaining footgun in C++ is the implicit numeric conversions. What else did you have in mind?

I mean, the default behavior of single-argument constructors in C++ is implicit conversion. You have to opt into explicit conversions using the `explicit` keyword on constructors and assignment operators.

Then you have all the shenanigans around placement-new and vtables.

If it isn't downright weak, it's also not particularly strong.

Re: Matt Godbolt sold me on Rust by showing me C++

#596

Earlier quoted context omitted.

It's a relatively new endeavor, but it's also a requirement in 2025 if you want to be portable. The Linux ecosystem was focusing on installing dependencies system-wide for decades (that's how traditional `./configure.sh` expects things to work), and this approach is just inferior in so many ways. The shenanigans people get into with CMake, Conan, vcpkg, and so on is a patchwork of nightmares and a huge time sink comp…

I don't think it's a requirement and it does actually come with it's own set of foot guns. The problem is that these design decisions impact culture, which is why JS has a culture of importing far too many third-party packages. Which comes with it's own set of risks. I agree overall that the C or C++ way of doing things is more cumbersome, but I don't think that's enough to write off those languages as a whole.

Certainly not enough to write them off on its own, but it is one of many problems.

Re: Matt Godbolt sold me on Rust by showing me C++

#597

Earlier quoted context omitted.

I don't see why you would have to write your own - there are plenty of options in the crate ecosystem, but perhaps you found them insufficient? As a video game developer, I've found the case for custom general-purpose allocators pretty weak in practice. It's exceedingly rare that you really want complicated nonlinear data structures, such as hash maps, to use a bump-allocator. One rehash and your fixed size arena blo…

> there are plenty of options in the crate ecosystem Who writes the crates?

That's public information. It's up to you to make the choice whether to trust someone, but the least you can do is look at the code and see if it matches what you would have done.

Re: Matt Godbolt sold me on Rust by showing me C++

#598
post #387
post #350

Earlier quoted context omitted.

> I just almost never have problems with this sort accidental conversion in practice. 95% of C++ programmers claim this, but C++ programs continue to be full of bugs, and they're usually exactly this kind of dumb bug. > will be noticed by literally just running the code once. Maybe. If what you're doing is "tricky mathematical algorithms", how would you even know if you were making these mistakes and not noticing the…

It’s the sociology of software development. The guild of software developers has no real standards, no certification, no proven practices outside and while continuing to depend on the whims of project managers, POs and so-caled technical leaders and others which can’t tell quality code from their own ass. There’s usually no money in writing high-quality software and almost everything in a software development project…

Software developers no, but Software Engineering does, it is a professional title in many countries, where universities and engineers are only legally allowed to use such titles after being validated.

Re: Matt Godbolt sold me on Rust by showing me C++

#599
post #383

I always enjoy reading articles like this. But the truth is, having written several 100s of KLOC in C++ (i.e., not an enormous amount but certainly my fair share) I just almost never have problems with this sort accidental conversion in practice. Perhaps it might trip me up occasionally, but will be noticed by literally just running the code once. Yes, that is an extra hurdle to trip over and resolve but that is triv…

This article presents something I’d expect competent C++ programmers with a few years of experience to know. Unfortunately, many programmers are not competent. And the typical modern company will do anything in its power to outsource to often the lowest bidder, mismanage projects and generally reduce quality to the minimum acceptable to make money. That’s why one needs tools like Rust, Java, TypeScript, etc. Unfortun…

Just like it happened with Scala and Kotlin, it is the Haskell they are allowed to use at work, and that is how you get such libraries.

Re: Matt Godbolt sold me on Rust by showing me C++

#600

Earlier quoted context omitted.

How can you simultaneously call cpp a mature language with mature tooling and acknowledge that there's no working package manager used by any "serious" project?

Package managers per language are a (relatively) new endeavor. The oldest language I can think of that widely adopted it was Perl. Although, perl was quite ahead of it's time in a lot of ways, and php undid some the work of perl and went back to popularizing include type dependencies instead of formal modules with a package manager. C++ "gets away" with it because of templates. Many (most?) libraries are mostly templ…

Anyone that cares about C++ package managers is already happily using vcpkg or conan, it is a solved problem.
Post reply on HN