Live data from Hacker News

Switching from C++ to Rust

laplab.me

11–20 of 289 posts

Re: Switching from C++ to Rust

#11

The call out to sum types is something I feel. I've been using Rust daily for almost 10 years now, and sum types are absolutely still one of the things I love most about it. It's easily one of the things I miss the most in other languages that don't have them. I'm usually a proponent of "using languages as they're intended," but I missed exhaustiveness checking so much that I ported a version of it to Go[1] as a sort…

Agreed. I don't have much Rust experience, but I do know Scala and Haskell and Typescript. It's one of those patterns that just comes up again and again and it's wonderful when the language offers a good solution.

And I must say that Typescript has the most flexible variation of it. I remember a while ago (> 10 years) that somebody on Lambda the ultimate asked how to flexibly represent compiler intermediate representations using the Scala type system, given that there can be many of them with overlaps. These overlaps are not a problem at all in Typescript.

Re: Switching from C++ to Rust

#12

The call out to sum types is something I feel. I've been using Rust daily for almost 10 years now, and sum types are absolutely still one of the things I love most about it. It's easily one of the things I miss the most in other languages that don't have them. I'm usually a proponent of "using languages as they're intended," but I missed exhaustiveness checking so much that I ported a version of it to Go[1] as a sort…

agreed, many language features have trade offs or limited usefulness, but after years in the profession I feel that sum types are something every language should have.

Re: Switching from C++ to Rust

#13
> How these commands change if I want to build the project with sanitizers? What do you mean the sanitizers are not supported by the build process? Why the build script suddenly started printing linker errors?

Doesn't Rust require you to switch to nightly to use sanitizers?

Re: Switching from C++ to Rust

#14

The call out to sum types is something I feel. I've been using Rust daily for almost 10 years now, and sum types are absolutely still one of the things I love most about it. It's easily one of the things I miss the most in other languages that don't have them. I'm usually a proponent of "using languages as they're intended," but I missed exhaustiveness checking so much that I ported a version of it to Go[1] as a sort…

Wait, are you saying that std::variant isn't a solution to all the problems? :D

Re: Switching from C++ to Rust

#15
post #5

The most fun thing reading this comparision is again that for an experienced C++ programmer who is used to managing memory by hand (and fixing segfaults), Rust's memory model doesn't seem that hard, because it makes sense, and he understands why the checks are important.

Rust's memory model is even more familiar to C++ programmers who don't manage memory by hand because they have the same concepts of borrowing and lifetimes.

You are still "managing" it even in that instance (just like in Rust). The overhead is just smaller than in say C or old style C++ with new/delete.

Re: Switching from C++ to Rust

#16

Earlier quoted context omitted.

Agreed. I don't have much Rust experience, but I do know Scala and Haskell and Typescript. It's one of those patterns that just comes up again and again and it's wonderful when the language offers a good solution.

And I must say that Typescript has the most flexible variation of it. I remember a while ago (> 10 years) that somebody on Lambda the ultimate asked how to flexibly represent compiler intermediate representations using the Scala type system, given that there can be many of them with overlaps. These overlaps are not a problem at all in Typescript.

Typescript has discriminated unions, which are amazingly nice

Re: Switching from C++ to Rust

#17
post #15

Earlier quoted context omitted.

Rust's memory model is even more familiar to C++ programmers who don't manage memory by hand because they have the same concepts of borrowing and lifetimes.

You are still "managing" it even in that instance (just like in Rust). The overhead is just smaller than in say C or old style C++ with new/delete.

The overhead is the same. Rust just takes care that you're doing it right, while C++ lets you shoot your foot off in this area.

Re: Switching from C++ to Rust

#18
post #15

Earlier quoted context omitted.

Rust's memory model is even more familiar to C++ programmers who don't manage memory by hand because they have the same concepts of borrowing and lifetimes.

You are still "managing" it even in that instance (just like in Rust). The overhead is just smaller than in say C or old style C++ with new/delete.

manually vs automatically (with more control about the how compared to other high level languages)

Re: Switching from C++ to Rust

#19

The call out to sum types is something I feel. I've been using Rust daily for almost 10 years now, and sum types are absolutely still one of the things I love most about it. It's easily one of the things I miss the most in other languages that don't have them. I'm usually a proponent of "using languages as they're intended," but I missed exhaustiveness checking so much that I ported a version of it to Go[1] as a sort…

so, um, unions? i have to say that in many years of programming, i have almost never needed to use such types.

Re: Switching from C++ to Rust

#20
post #5

The most fun thing reading this comparision is again that for an experienced C++ programmer who is used to managing memory by hand (and fixing segfaults), Rust's memory model doesn't seem that hard, because it makes sense, and he understands why the checks are important.

Rust's memory model is even more familiar to C++ programmers who don't manage memory by hand because they have the same concepts of borrowing and lifetimes.

I was just trying to find a modern C++ tutorial, but there's nothing comparable to the Rust Book on the internet.

I think even now the best resource to learn C++ is to first learn C, then original C++, then all the modern memory management techniques, which is just crazy hard for a new programmer compared to just going through the Rust book 10 times (which is needed to get a deep understanding).

Post reply on HN