Live data from Hacker News

Ask HN: Learn C++11 or Rust in 2022?

news.ycombinator.com

51–60 of 161 posts

Re: Ask HN: Learn C++11 or Rust in 2022?

#51
> I see a lot of criticism/hate of C++ lately (mostly due to the comittee), but the tooling and libraries are there for multiple areas.

I like C++ and my main caveat is that you don't just write C++. You also have to get good at tools like Valgrind and develop a deep intuition and understanding of what the language does under the hood. That's going to require a significant time investment and some people just don't have the right energy for it.

Nowadays the only reason I would learn C++ instead of Rust would be if I wanted to benefit from the much bigger C++ ecosystem, for example to build a game engine from scratch.

Re: Ask HN: Learn C++11 or Rust in 2022?

#52
post #35

I would choose Rust. Today it might be that the market has more jobs on C++ and there are more codebases. In the future, those codebases will only be the legacy ones and you will end up doing more maintenance with C++. With Rust your investment of today will pay off in a few years. Deciding what to learn today is an investment decision and you should look into what you think the future will look like. To me it looks…

I think a valid concern might be - in 5 or 10 years, C++ still remains, just like Java and other "boring" languages. However, Rust might have been replaced by the next "Rust". That environment is still somewhat in flux.

I agree with you, it might turn out that C++ outlives Rust. I am seeing more codebases being created from scratch in Rust nowadays. We are just making bets on the opposite side. I guess we both agree that the deciding factor should be what you think the future will look like in 5+ years. Nobody knows what will happen in 5 years, then it is a bet or an investment decision you make.

Re: Ask HN: Learn C++11 or Rust in 2022?

#53

Earlier quoted context omitted.

Honestly my main short-time goal is to write performant applications, I have some processes in mind that would work way better if I could manage memory instead. At the moment I just write bits in C whenever I need it but when it scales in a decent size I would just write the whole thing in C++/Rust

With C++ realistically memory management is so hard that if you want to go solo, and you don't want to debug segfaults all the time, Rust is definitely the way to go. It teaches you manual memory management like nothing else.

I took an Earley parser library written in Java and ported it to C++ with just using smart pointers everywhere for memory management and it Just Works™. Like magic really as I can’t recall having to hunt down any segfaults and I spent a bunch of time debugging that thing because porting from Java wasn’t really a copy paste operation especially since I never mess with Java so don’t know the standard library stuff.

Re: Ask HN: Learn C++11 or Rust in 2022?

#54

Earlier quoted context omitted.

Honestly my main short-time goal is to write performant applications, I have some processes in mind that would work way better if I could manage memory instead. At the moment I just write bits in C whenever I need it but when it scales in a decent size I would just write the whole thing in C++/Rust

With C++ realistically memory management is so hard that if you want to go solo, and you don't want to debug segfaults all the time, Rust is definitely the way to go. It teaches you manual memory management like nothing else.

Unless you're manually implementing data structures or something similar you basically never need to manage your memory manually in modern C++. std::vector takes care of most your needs and smart pointers exist for the few cases where it doesn't. There's not really a lot of difference to Rust there except that OOB access is a panic in Rust and (most likely) a segfault in C++ but you can trivially enable that checking by putting the STL in debug mode.

C++'s problem is that most people never learn it properly and think "C/C++" is a thing because most courses/tutorials are stuck in the 90s and effectively teach shitty C with classes and iostream. Rust is great and has really nice features which I'd like to have in C++ too (like pattern matching) but memory safety is really not an issue in proper modern C++. I'm aware that this is a bit of a "you're just holding it wrong" but pretty much all languages have things you shouldn't do anymore once they evolve, it's just more obvious in the one with strong backwards compatibility requirements to the ancient language created before all the modern research into language design.

Re: Ask HN: Learn C++11 or Rust in 2022?

#55
post #2

Between C++ and Rust, my bet would be that you decide Rust. But—also learn Zig in addition to Rust. Having seen first-hand how so many threat vectors these days are now supply chain attacks, having reported CVEs and earned P1 bounties in memory safe languages, and having worked on static analysis systems to detect zero day exploits—I'm also impressed by Zig's overall approach towards safety, as being more than only m…

I'm confused when people preach Zig and then safety in the same sentence. Zig has basically all the same problems that C++ has with a few extra bells and whistles. There are perfectly good reasons to like Zig, but it being "safe" is not one of them. > For example, this comes through in little things like Zig's extreme simplicity and explicitness "Simplicity" does not mean safety. In fact simplicity means you can't de…

> In fact simplicity means you can't describe hard problems easily without being overly verbose, which means more code and more attack surfaces.

Hence simplicity is not a desirable goal. We need to create complex languages so that fewer people can understand and use it in a few projects and write very less code. Less code means less bugs. ‘Complex’ is the way to go. /s

Re: Ask HN: Learn C++11 or Rust in 2022?

#56
It depends on which direction you want to go.

Rust is probably a better bet for web-related things. There is not much C++ there, and Rust seems to get some popularity. After all, Rust was originally made for Firefox.

For more industrial applications, or game dev, C++ is likely the way to go. Where I work, we do a lot of industrial applications and we have a lot of C++ projects, including new ones. Rust is not even on the radar. [Edit: C++ here is mostly C++11 now, with some C++98 and not much C++14 and later, I expect that we will get to C++17 soon enough but C++20 probably has a long way to go]

Forget about the criticism/hate of C++ and hype of Rust, it has little to do with practical applications.

Re: Ask HN: Learn C++11 or Rust in 2022?

#58
post #2

Between C++ and Rust, my bet would be that you decide Rust. But—also learn Zig in addition to Rust. Having seen first-hand how so many threat vectors these days are now supply chain attacks, having reported CVEs and earned P1 bounties in memory safe languages, and having worked on static analysis systems to detect zero day exploits—I'm also impressed by Zig's overall approach towards safety, as being more than only m…

I'm confused when people preach Zig and then safety in the same sentence. Zig has basically all the same problems that C++ has with a few extra bells and whistles. There are perfectly good reasons to like Zig, but it being "safe" is not one of them. > For example, this comes through in little things like Zig's extreme simplicity and explicitness "Simplicity" does not mean safety. In fact simplicity means you can't de…

> I'm confused when people preach Zig and then safety in the same sentence.

Zig enforces correctness much more than C or C++ does (e.g. no implicit 'lossy' conversions, much stricter and enforced error handling, no implicit null, etc.), so it's completely fine to say that Zig is much safer than C or C++.

The main difference between Zig and Rust is the borrow checker, but a lot of memory corruption issues in C and C++ are "second order effects" of sloppy code which would be caught in Zig either at compile or runtime.

Re: Ask HN: Learn C++11 or Rust in 2022?

#59
post #44

Not for everybody, and I’m sure it’s not the most efficient way to approach it, but I personally felt that learning modern C++ was a good intermediate step before learning Rust. Going to rust directly has been a very frustrating experience and made me give up. Instead I spent time learning C++, I found out I could more easily transfer my knowledge/skills there. Once you become more proficient with the basics you lear…

> Going to rust directly has been a very frustrating experience and made me give up.

IMHO, you could learn Rust as a first PL by treating it as a functional programming language with a focus on purity, like a twist on ML or F#. The borrow checker rules and things like the String/&str distinction follow naturally from that POV. Then learn how "interior mutability" is used to enable more C-like procedural programming with shared mutable state.

Re: Ask HN: Learn C++11 or Rust in 2022?

#60
I think you should tinker enough with both languages to learn their main concepts and then let 'outside requirements' guide you from there. E.g. if you're looking for a C++ or Rust job, or want to contribute to a C++ or Rust open source project, or just generally enjoy one language more than the other for weekend projects.

Also, if you're already fluent in another imperative programming language, it shouldn't take more than one or two weeks of a few hours after work to get an initial grip on both languages and decide whether you like them or not.

Personally, I find both languages equally frustrating for 'spare time stuff' (for different reasons though) and prefer simpler languages like C, Zig, Go, Python or Typescript (depending on the problem at hand).

Post reply on HN