Live data from Hacker News

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

news.ycombinator.com

61–70 of 161 posts

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

#61
post #11

Unless you're going to be doing something that specifically requires C++ (some game engine related code comes to mind), go with Rust. Most real-world code (by number of codes and lines of code) is something else than C/C++ nowadays, just because of developer velocity and a larger hiring pool. Yes, you can get that last cycle of power from a piece of hardware by going with C or C++, but on the other hand finding peopl…

How do you begin to get paid for it without studying it first?

Some employers are actually far-sighted enough to spend money training their employees.

So e.g. you hire a bunch of fresh graduates who've learned some programming maybe Java and Python, and maybe have other expertise you value (e.g. maybe they're aerospace engineers and you write control software for jet engines) and you spend money hiring somebody capable to stand at the front and teach them how to write C++. It's their job to learn this, so you can do it pretty intensively, e.g. lecture slot / exercises / break / repeat.

C++ is a big sprawling language, but you can make a good start on them in two weeks.

You've presumably worked somewhere with at least some onboarding or spin-up time. Somewhere you weren't employee #1 and responsible for buying your own stationery and cleaning the toilet ? What did you do on day one? Fire training? How to use the CI system? Anti-bribery? Getting your photo taken for an ID badge? Maybe some "easy" first tasks just to learn your way around the systems?

If you have a job where you turn up on day one and are just as productive as a long haul employee, I have terrible news for you - you are the most replaceable person in your organisation and you are going to get fired.

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

#62
post #27

Earlier quoted context omitted.

When the car's automatic gearbox breaks down, it is nice that there are some mechanics around.

True, but not everyone with a license needs to know how to rebuild a gearbox =)

Depends, on some countries getting a license means acquiring basic repair and first-help skills. :)

In any case, the point was that those that know how to repair the gearbox must come from somewhere.

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

#63
post #30

C++ has a myriad of wonderful language features that exist entirely within C++ and cross no language boundaries. I really adore C++ as a language but unfortunately I find little pragmatic use for it unless I'm working 100% inside C++ and using native APIs only. If you're doing that, it's a dream. Rust, on the other hand, speaks the same ABI as C, and with serde, can read and write to most formats and/or APIs with utm…

> C++ has a myriad of wonderful language features that exist entirely within C++ and cross no language boundaries. I really adore C++ as a language but unfortunately I find little pragmatic use for it unless I'm working 100% inside C++ and using native APIs only. If you're doing that, it's a dream. Rust, on the other hand, speaks the same ABI as C, and with serde, can read and write to most formats and/or APIs with u…

I find it difficult to articulate, so forgive me if I'm not getting my point across, but the gist of what I'm trying to say in that section is less about straight binary compatibility and more about API design in general, playing to the respective language's strengths. I feel like Rust encourages more "C-like" APIs, and its added features (such as memory safety) are in effect the whole running time of the program, regardless of where that memory comes from or how it's initialized. On the other hand, C++ has something of a vendor lock-in regarding how it functions - RAII, constructors, exceptions, inheritance, etc. etc. all assume you have objects with a lifecycle that starts and ends in C++, and that those objects see most of their use according to C++'s object model. All of C++'s features come together in a brilliantly harmonized way and build off each other, but, if you forgo even some of those features, you end up missing out on most of them.

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

#64
Rust - assuming something these languages are uniquely-suited to, like embedded, drivers, OS programming, or 3D graphics. It's a smoother experience in most areas. For example, I find it to have cleaner, more explicit syntax, good included tooling, and is easier to compile. Things like blocking implicit number conversions, and specifying array types (or array references) instead of pointers are nice.

A warning: Rust as a language has a large surface area, and there are some features and design paradigms that can make it messy to read and write. I would treat generics as a tool to be used sparingly, vice as a default API, for example. Same with Async and Tokio.

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

#65
Since it looks like you want to use it for some personal projects and you’re already comfortable with C, I’d suggest C++.

I’ve found that Rust requires more careful design to satisfy the borrow checker, whereas in C++ you’d just copy or use a smart pointer and move on with life. Additionally, when in Rust you have to change that careful design, the changes tend to cascade and spread.

All of the above could be largely avoided by using copying and smart pointers also in Rust, except that goes against the culture and what everyone else is doing. Most of the APIs you’re using will probably want you to use references…

To me Rust is the kind of language you’d use if you have your solution figured out and you want to implement a robust program based on that. Flexibility and development speed are not its strengths.

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

#66
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…

Counterpoint: Zig is unstable (as in, Stick to C++ or Rust, which I won’t weigh in on here. But both are much more mature.

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

#67
Here’s a fun way to decide. Do Raytracing in One Weekend[1] in one of them. Then rewrite it again in the other. That should give you a good sense for which one you want to invest in.

Spoiler: I did this exercise myself. I found Rust to be more convenient in some ways. The Rayon crate made adding parallelism (threads) pretty easy. Some other crates made things pretty terminal output easier.

C++ feels more familiar to me in many ways though - I also write C fairly often. Implementing parallelism was more difficult. (I tried `pragma omp` stuff which should work similarly to Rayon, but couldn’t get it to work.) But just getting something working seems a little more straightforward.

I find myself fighting Rust somewhat often. In C/++, if you know what you’re doing, and you just want something working as a fun side project, it usually takes less dev time in my experience. Maybe that’s because I’m still learning it. Some folks will argue that the Rust compiler forces you to write better code and actually makes dev faster because it catches your mistakes. I haven’t found this to be true.

For example trying to implement simple polymorphism in Rust that was analogous to the implementations in Raytracing Weekend got ugly very fast. I ended in a weird hell of having to add annotations to everything to support generics. Again maybe I don’t understand the language enough, but adding polymorphism was a 5-minute straightforward exercise in C++, even as someone who doesn’t write it often.

I like a lot of stuff about Rust but I’m doing my hobby dev stuff in C instead nowadays, mostly for dev speed like I said, and probably would opt for using a subset of C++ for higher-level projects.

[1] https://raytracing.github.io/books/RayTracingInOneWeekend.ht...

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

#68
TLDR; Learn both and choose the right tool for the right job.

Now, for C++ I can share some links I personally follow:

    https://github.com/AnthonyCalandra/modern-cpp-features
    https://www.youtube.com/c/lefticus1/videos
    https://www.fluentcpp.com/
    https://www.cppstories.com/
    https://hackingcpp.com/
    https://www.modernescpp.com/
About Rust, this link https://www.rust-lang.org/learn shares far too many goodies that any level of programmer can benefit out of it.

Enjoy!

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

#69
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 w…

I feel that by starting with FP, for example by starting with something close to ML in syntax and concepts, you cut yourself from too much of the programming world as everything else feels completely foreign and weird. But I get your point, you can approach it from the other side and also develop your intuition this way.

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

#70
I remember when Stroustrup's C++ came out in 1986. I used to be able to cite the Annotated Reference Manual (ARM) by chapter and verse. But if I were a young programmer in 2022 and looking at learning either C++ or Rust I'd choose Rust in a heartbeat.

Why?

Many reasons. For starters, C++ is 40 years old at this point and embodies software engineering practices from the late 70's to early 80's (for you young folks, structured programming was the new hotness in the 70's!) C++ was also designed to take advantage of C's tooling, or lack thereof. C had incredibly simplistic dependency management. It worked well for the time since there were very few external dependencies, almost the entirety of the codebase was hand-built by the entity creating the software. There were very few libraries outside of the standard libraries.

C++ has an object model making it difficult to use and extend objects from different code bases/libraries. Never mind the inheritance patterns leading to lots of confusion. Just remember, Java and later C# were created to address these issues with C++. They were both touted to be better versions of C++ (which was true in the application development space where a GC could be tolerated)

Finally, the C++ type system is barely a type system as we understand them today. That's just history - C++ reflects our best thinking from the 70's and the modern type systems started emerging in the 80's. The simplicity makes some things unduly burdensome to implement.

Don't get me wrong - I've programmed in C++ for decades and I like it, warts and all. But I'm also practical and I recognize its days are numbered. Will C++ be around in 20-30 years? Absolutely! But so is Cobol, and would you start a major project today using Cobol? No. You can see we're shifting from C++ to Rust. C++ is the past and the lion's share of the present but Rust is gaining on the present and is the future. If I did't know either Rust or C++ in 2022 then I would focus my efforts on learning Rust.

Post reply on HN