Live data from Hacker News

Ask HN: Should I learn C++ in 2021?

news.ycombinator.com

1–10 of 44 posts

Ask HN: Should I learn C++ in 2021?

#1
Hello there,

I‘m in a bit of a pinch. I‘m currently part of a team that needs help with C++ development.

My background is around 9 years of iOS / macOS development using ObjC / Swift and a few projects using C#.

In the recent months / years I tried to hone my software-craftsmanship and stay up-to-date on stuff like TDD, functional programming, protocol-oriented-programming, moving away from objects, and so on.

I could help out my team and my employer by diving into C++. However I have some prejudices which I want to sort out:

- I’m hesitant towards C++ as it seems an ancient programming language and I don’t know for how long it will be around.

- I‘m hesistant on investing time into C++ as I don’t know how much acquiring this language as a skill will help me advance my career as a software-developer.

Could you provide some pro/contra arguments?

Best wishes from Southern Germany

Re: Ask HN: Should I learn C++ in 2021?

#2
C++ is a really great language and it gets a lot of bad press because many people use it very wrongly. Are there bad things you can do in C++? Surely! But I feel a large amount of the bad press it gets is because many _refuse_ to use RAII or refuse to use parts of the STL library that are battle-tested. (https://en.wikipedia.org/wiki/Resource_acquisition_is_initia...)

There are a lot of reasons to learn C++, but the turnaround time isn't great. If you don't know the language at all right now the time it will take until you can likely provide meaningful changes to your team could be months away. One counter argument to that is that having fresh eyes on an old problem can yield useful results sometimes, similar to rubber ducking. (https://en.wikipedia.org/wiki/Rubber_duck_debugging)

As for C++ "not being around" anytime soon, very unlikely. C++ has outlived many languages and will continue to outlive many more. Virtually any major web browser you are using (or it's primary components) right now to view this page are C++ based. (https://en.wikipedia.org/wiki/WebKit)

Re: Ask HN: Should I learn C++ in 2021?

#3
> I’m hesitant towards C++ as it seems an ancient programming language and I don’t know for how long it will be around.

It will be around for a long time. This shouldn't be a reason not to pick up C++.

> I‘m currently part of a team that needs help with C++ development.

That might be a good sign that you should pick it up but the details matter a lot. Getting to the point where you're productive with C++ in an existing codebase takes a while even for people who are experienced with the language let alone someone who is just learning it. So I would invest the time to learn C++ for work only if it's a long-term project where you'll have the necessary support from the rest of the team and from your engineering management. You need to establish the expectation that you can't just jump in and immediately make meaningful contributions. If it's a case of "this old C++ repo runs a critical piece of our product and we need a person to make some changes and maintain it", then stay as far away as possible.

Re: Ask HN: Should I learn C++ in 2021?

#4
To be honest if you know C#, Java or ObjectiveC you already know the core 90% of C++.

The main thing left is understanding pointers vs references vs stack vs heap allocation (egthe instance.x vs instance->x difference) because C++ has those explicitly different pointer vs non-pointer intances of "instance", while C# or Java hide that difference (so if you know C# you can slightly think of it as struct vs class in C# difference since struct is copy-by-value while class is always a reference (a pointer).

Moving away from objects doesn't make sense: objects are perfectly fine and usable. It all depends on the context. Anyone who says "don't use objects" is a religous zaelot who does't see the forest for the trees anymore. For certain extreme performance cases objects can be bad, but in ~95%+ of cases objects are perfectly fine. We are again starting to enter "it all depends on the context" territory.

IMO C++ got some very bad rep for no reason at all: it got mythologized into a "very difficult arcane language that people makes meme about". So because of this people think C++ is some boogey man, while it's really not. Unless you are making life-critical software like avionics it honestly isn't much more difficult than C# or Java.

Ironicaly you already understand the difference between pointer and non-pointer since you know instinctively that an "int" type is will get fully copied while in Java a class object is a reference (pointer). C++ just makes this even more explicity since YOU can decide if a class is a copy-by-value or a reference on the fly (assuming the class doesn't have complex sub-fields inside of it that require their own complex copy-by-value vs reference rules).

Also due to C++ being mythologized as an "super difficult language" you get some extra XP on resumes if you state that you know it.

Re: Ask HN: Should I learn C++ in 2021?

#5
>C++ as it seems an ancient programming language

Sometimes, the counterintuitive situation is that the "ancient language" is the tool that enables you to write the most modern cutting edge application. My previous comment about this: https://news.ycombinator.com/item?id=25315815

>I‘m hesistant on investing time into C++ as I don’t know how much acquiring this language as a skill will help me advance my career as a software-developer.

It will help your career if you become highly skilled at C++ and it's easier and more realistic to build competency if you have interesting projects that require C++.

In other words, a lot of people don't learn LanguageX because of some elegant syntax feature or a vague "future value". Instead, they learn a new language because an interesting runtime or target environment requires that particular language.

E.g. I previously ignored Python for years. But now I learned it not because I like spaces as indents instead of curly braces or because of Python mantras such as "One True Way To Do Things". I learned it because the new field of AI machine learning interests me and the lingua franca in that topic is mostly Python and not C++. I learned Visual Basic because that's the language of Excel macros. I learned Bash because that's the default shell in Linux. And so on.

In summary, C++ would be easier for you to pursue if the problem domains that C++ is good at are areas that naturally appeal to you. Stuff like close-to-the-metal coding such as backend server processing, high-frame-rate video games, etc. Is your team's C++ code base interesting to you? If not, learning C++ will be a slog.

Re: Ask HN: Should I learn C++ in 2021?

#6
C++ is vast and diverse, but if you have interest in functional programming you may actually end up enjoying C++, since thanks to it's value types and it's imperfect albeit powerful type system (it's a bit like a compile-time dynamic typing, allowing interesting translation of Lispy patterns). I'm actually on a mission to build a solid ecosystem of functional and value-oriented tools for C++ and interactive software, some of which are used by big companies like Google:

https://github.com/arximboldi/immer

https://github.com/arximboldi/lager

https://github.com/arximboldi/zug

Also, I very agree with what @jasode has said. C++ will be interesting for you if you can do interesting things in C++. That is the main reason I use it: there are certain domains where I work: professional music software, graphics, film, robotics, etc. where there are no solid alternatives (maybe Rust/Nim/Zig if you are very adventurous). This kind of software is actually really cool, it's creative and enhances artists's lives and does not live in magical "clouds" but runs on your machine. The language is imperfect and complicated but working in these domains is really cool and it makes the experience of taming the beast of C++ enjoyable :)

Re: Ask HN: Should I learn C++ in 2021?

#7
Pro (Arguments for learning C++):

* It will massively increase your marketability: C++ is one of the most popular languages around, and it will stay this way for at least 10-20 years. Most desktop programs are still written in it, most AAA games, and most operating systems, most multi-media data processing uses either C or C++, and it's still the most popular language in the embedded space. Wherever execution speed is a goal, C++ is the lingua franca. As an iOS dev, these might be markets you didn't consider before, but knowing C++ will go a long way towards unlocking them for you, should you ever want to go into them. It will increase the potential places of employment for you like very few other languages could.

* C++ is powerful. It lets you do stuff that's out of reach in a lot of other languages. Have you ever thought "gee, this inner loop costs too much runtime but is easily vectorizable. Man I wish I could hardcode this piece of code in SSE intrinsics (or other modern CPU instructions) or write inline assembly"? Or "man, I could actually already compute this at compile time if the processor would let me" or "If I could store this information in the upper bits of the memory addresses that go unused, I could squeeze the data in a cache line, making cache misses almost a non-issue"? C++ makes these things (and many others) available to you, if you ever want to.

* It will massively increase your software-craftmanship: There are very few popular languages that will expose you to such a breath and depth of programming language concepts, From bare-metal pointers and references, manual memory management & smart pointers to template metaprogramming. At least for me, no other programming language has given me this many instructional "aha" moments, because C++ makes a lot of stuff explicit that is just hidden away in most other languages. Even if you end up not using C++ much later on, knowing and understanding the concepts of C++ will make you a much better programmer in other languages as well. And will make learning other new programming languages much easier. Haskell and LISP are the only two languages I can think of that had similar effects for me.

Contra (Arguments against learning it):

* C++ is difficult. It has massive footguns and error messages (especially in templated code) are sometimes not very helpful. A lot of things that are easy in other languages are suddenly hard, and manual. Some bugs are absolutely non-trivial, hard to understand and to debug, on a level that you haven't seen before. With great power comes great responsibility.

* C++ is old: This may just be a riff on "it's difficult". But on several occasions, it'll get on your nerve. The build and link system are outdated. And C++ in 1998 looked different than C++ in 2017. And the language is still evolving.

Re: Ask HN: Should I learn C++ in 2021?

#8
I’m hesitant towards C++ as it seems an ancient programming language and I don’t know for how long it will be around.

As a rough rule of thumb, the older a language still in use is, the longer it will be around into the future. I believe C++ will outlive you.

Re: Ask HN: Should I learn C++ in 2021?

#10
As others have said, I wouldn't worry about C++ going anywhere soon. The sheer amount of historic code out there, and the difficulty of replacing that code with any of the potential alternatives mean the language is still likely to have decades of life in it, even if it did not continue to change and evolve.

Whether a change to more C++ development will be good for either you or your team is a more open question. I was primarily a C# developer and got into C++ because I ended up in a company where it was being used and had to be supported. I have never coded in Swift and have done almost nothing with objective C, so I will not comment on them. I have been coding periodically in C++ for the past five years, and to me it always feels slower, more difficult and less enjoyable to write something in C++ than to do the same thing in C#

It is true that C++ is a powerful and flexible language and there are places where you will be hard pressed to find anything that works as well as it in terms of raw performance or fine grained control. But because of its age, many features which can be taken for granted in a language like C# have had to bolted on to C++ and lots of those bolts look ugly. There is also a lot in the language, and if you're going to use a language feature then it really helps to understand it in depth, because its depressingly easy to write code that is badly wrong in ways which will not be easy or quick to detect.

If your team's need for C++ support is going to be a long term thing (ie they're still going to be needing you to work on this stuff a year or more from now) then it may be worth their time and yours bringing you in to work on the language. If not, you may well cost more in terms of what it takes to get you up to speed than the benefit once you are fully productive. (This, of course, will vary depending on many factors such as the quality of the code base, the range of language features it happens to employ, the amount of support you can expect from your co-workers and how competent you are at learning a new language. These are things that only you and your team are able to decide.)

Post reply on HN