Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: Should I learn C++ in 2021?
40 points by flowinho on March 11, 2021 | hide | past | favorite | 42 comments
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




Just a few things you should consider: - C++ is highly complex. The poster lower down claiming you already know 90% if you know C#/ObjC is simply wrong. The learning curve is steep. - Your stated experience sounds a bit like "App developer" and while that gives you plenty of experience, the projects tend to be a bit smallish. C++ projects on the other hand can be huge and extremely complex. Think 4 hrs for a clean build, with 10+ people working on the same code base. You should consider if such a change is for you. - Then again, the salaries you can draw as C++ developer reflect all that, especially the fact that C++ is not an easy language to pick up. - Since you claim to be from Southern Germany: the automotive industry is particularly strong in that region. And not only in Stuttgart or Munich but also in e.g. Ulm. And they do most, if not all, their stuff in C++. - C++ is going to stay. Software development for automotive is done in C/C++ as the MISRA standard more or less mandates it. And I do not know of any effort to change that, even by newer players in the field. So: don't worry. Learning C++ to a sufficiently advanced level will be a very good career investment, even in the long term. - It is difficult to "vet" language in terms of the future they have. But as a rule of thumb you can say: the larger / more complex the code base, the longer the language will be around. C++ has a huge and complex code base, and companies tend to be conservative with such "investments". Shipyards still use Fortran, banks still use COBOL. Perl is still actively used in web development, despite Ruby on Rails. - Finally: perhaps you are looking at the whole situation from the wrong angle, i.e. career advancement / employer loyalty. Why not instead ask yourself: what projects do I want to work on, and in what kind of industry? Then find out which language is pervasive through that domain and learn that. After all: C++ is modern compared to C. And there is still plenty of embedded development going on in C.


> C++ projects on the other hand can be huge and extremely complex. Think 4 hrs for a clean build, with 10+ people working on the same code base.

I'm not sure what this has to do with the language itself or why you think other languages don't also have large projects written in them.


OP sounds like an app developer. They are saying that apps typically aren’t projects of that size


And plenty of C++ projects also aren't projects of that size. I'm not sure what that has to do with whether or not OP should learn C++. Should OP not learn C because the Linux kernel is written in it?


Don't know why you're downvoted because you're absolutely right. Just because some very large C++ projects can take hours to build, I'd say this is not true for the majority of projects.


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

Twenty years ago, I learned Delphi rather than C++, because I thought C++ is an ancient language, and Delphi was modern.

Now Delphi is basically dead, and C++ is still around.


Lindy Effect:

> The Lindy effect is a theorized phenomenon by which the future life expectancy of some non-perishable things like a technology or an idea is proportional to their current age, so that every additional period of survival implies a longer remaining life expectancy

Example:

> If a book has been in print for forty years, I can expect it to be in print for another forty years. But, and that is the main difference, if it survives another decade, then it will be expected to be in print another fifty years. This, simply, as a rule, tells you why things that have been around for a long time are not "aging" like persons, but "aging" in reverse. Every year that passes without extinction doubles the additional life expectancy. This is an indicator of some robustness. The robustness of an item is proportional to its life!

https://en.wikipedia.org/wiki/Lindy_effect


And I use both!

C++ has new versions every three years, and Delphi is still widely used, just not well-known in the English-speaking dev work.


> 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.


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)


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 :)


What's funny is the move toward value types as trendy right now, meanwhile 10 years ago I was writing copy constructors in C++ to control the value semantics of values.


Yes, I agree! However, I think move semantics and standardization of RVO/Copy Elission have been crucial to make value-semantics work at scale.


>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.


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.)


I learned C++ at the start of my software career. I am glad I did; but I am also glad I never had to write it commercially.

Learning C++ makes learning other languages easier. It's C++ that made me grok the difference between stack and heap allocations; it taught me about moving semantics, dynamic arrays, reference counting garbage collection, data structure alignments, dynamic/static linking, segmentation faults and many more things.

The above things made me understand better how other programming languages work under the hood.

At times I find C++ code that is of intrinsic interest to me. Bitcoin, for example, was authored in C++. However I dread writing C++ because I find it very complex and it has outdated coding environments. Thus I am very happy I don't have to write it.


Forget what HN likes. A large proportion of software that people actually use, like the browser they're using, is written in C++. It isn't going away anytime soon


I agree on this, most of our software is also powered by C++ such as trading systems,our defense software,popular databases such as MySQL and even popular games


I think another very important question to ask is "What version of C++ will you be using?" Is your companies codebase stuck on a pre 2011 version of C++ for some archaic reason? If so, I would be less inclined to touch that codebase.

Or is the codebase using a relatively modern standard (such as C++17 or C++20?)

Does the team track new versions of C++ upgrade every 3 years so your not left behind?

Remember if your not upgrading, it means you and your team is not able to take advantage of the latest C++ features. For example C++ 20 brought lots of goodies such as Modules, CoRoutines, Concepts and a new Ranges library.


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.


definitely learn C++ if you are interested about how computing works "under the hood" of modern high level languages

even if C++ went away next year (which it won't, and you can be sure c++ will be here until eventually quantum computing takes over ;) the concepts and understanding of computing you'll learn is still valuable

in terms of advancing your career as a developer, realistically speaking it will advance your career most probably only if you make a switch to jobs that require real time / embedded / high performance / security. for other fields of programing today, c++ level of understanding will not advance your career as much as being a good communicator, acquiring connections and brown nosing


Hmm...I think a lot of this discussion is missing two important points:

1. Regardless of whether or not C++ is going away, your team needs help now. You have an opportunity to get up to speed and add value in the present. That could pay off in social capital, promotion, or just plain old appreciation of your efforts.

2. Say you don't care about your team's needs at all (for the sake of argument, I'm sure you do!). Learning C++ will teach you concepts and patterns that can help you be a better engineer, even if you move on to Rust later (which IMO will be C++'s replacement for new projects eventually). Growth happens outside your comfort zone, this could be a good growth opportunity.


I think it's always a good idea to learn as many different paradigms as possible. It also really depends on what direction you want to take your career/what the C++ team at your company is working on. C++ will be king for high performance, real-time compute for a long, long time. I work for a VR company making a VR-specific game engine, and C++ is pretty much the only game in town for extremely high performance, real-time graphics. So if you're interested in taking your career in the direction of high-performance, real-time systems then C++ is a great language to learn.


TL/DR: The answer depends on what you want to do. If you want to sell ads in google or facebook, you’re right to be hesitant. If you want to build Windows kernel in Microsoft or VFX in DreamWorks, I think you do need C++ even in the long run (at least couple decades).

C++ and similar unsafe languages have lost majority of the markets they once had. When I started my career in 2000, it was used for pretty much everything, people wrote C or C++ for desktop, web, mobile (PalmOS, later Windows CE), embedded (was mostly bare metal back then).

Over these 2 decades, it’s mostly gone from desktop (initially replaced by Java and C#, and now being replaced by JavaScript and TypeScript), gone from web servers (Java, then Ruby, then JavaScript/TypeScript), gone from mobile (Obj-C in iOS and Java in Android), and I think being slowly replaced even for embedded, I personally shipped embedded Linux stuff based on .NET Core.

Whenever you don’t care about performance too much, and have enough RAM — higher level memory safe languages are strictly better, IMO.

Still, there’re large areas when it’s unlikely to be replaced any time soon. Game engines are written in C++. Many low-level performance critical things like database engines are written in C or C++. C++ is all over CAD/CAM/CAE, 3D modeling and animations, VFX, everything related to multimedia (video streaming, processing, editing). And even some embedded: since you’re southern Germany, there’s probably a lot of work in automotive sector.

I think C++ is here to stay in most of these areas. When you have working set measured in gigabytes and want your software to be fast, the “have enough RAM” requirement of GC runtimes is often a showstopper. Large RAM requirement is expensive for code running on servers, and shrinks potential user base for code running on clients. There’re other things too: tooling, library ecosystem, performance in the broad sense.


I've recently decided to learn c++. I've used Java for over a decade and have had felt little reason to learn c++ until now.

What changed? There is code I need to do maintain in c++. If I don't do it, it might not happen.

Sounds like you are in a similar situation.

It feels weird learning a language competing with a HN darling (Rust), but I have the need.


Ha! C++ is not going away, probably not ever but certainly not any time in our lifetimes.

There is a LOT of code in C++ out there. I write in it every day. There are a lot of open source project written in C++.

C++ isn't even that hard to learn, at least to a basic level of fluency, but there is a lot to know to be good at it.


> I don’t know for how long it will be around.

Probably decades.

Things written in C++: web browsers, video/photo editors, audio software, compilers, and generally everything that needs the highest possible performance.


I think Nim is a better bet. It's safer and has a Pythonic syntax. However it's popularity is taking a long time to build, although I'd say it's getting there.


My question is that lets say if someone does want to learn C++ what are some good resources out there that someone can consume, considering video courses or even books


There's the c++ crash course book from nostarch. It's very comprehensive and teaches modern c++ nicely. For video courses Kate Gregory has some well received courses on modern c++ on pluralsight.


Oh ok thanks for suggestions I’ll check them out


Another question is how fast you can get into actually solving problems, since you're in a team, there is also an option of hiring a C++ developer.


I'm actually on the same train right now, are there any good learning resources to get into modern C++(CPP17/20)?



If you are starting with C++ right now, I'd suggest Scott Meyer's More Effective C++ (and his other books) and the books by Herb Sutter. Don't worry too much about C++ 17/20 unless you are working for a company that use the newer standards. A lot of companies still stick to C++ 11.


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.


hey


No


I've ever understood these kind of questions. IMHO never learn a programming language just to learn it. Actually, I would go further and say don't even study for a CS degree. Programming has become more popular now a days, with designers, marketers, financial people and others learning to program in their domain languages. The barrier to programming is even getting thinner with the advent of low-code platforms.

Than being said, my advise is to study for a domain that interest you, for example I am a Control Engineer. Then learn the programming language of your domain.

In my domain the design language is Matlab/Simulink, then when I got into the job market I realized that my career would benefit by learning 61131 (PLC languages), C and C++. So I learnt that. Now I am very good with the Qt framework, for example, which allowed me to enter a broader market of industrial application development.

So stop looking for an language to learn and better look for a domain that will ensure that you will have a job in the future. Then learn the language of that domain.


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.


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

If we change 90% to about 20% then this becomes a true statement. Yes, you can get toy code to compile and apparently work by pretending C++ is Java with some low level stuff that can be ignored, but that's nowhere near proficiency. The language is full of seemingly obvious concepts like static initializers that function unlike what you'd expect from working with C#, Java, or even C.

> 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".

It got that reputation on account of having an 1853 page standard that even members of the committee admit no one of them fully understands.

> C++ just makes this even more explicity(sic) since YOU can decide if a class is a copy-by-value or a reference on the fly

And this is why it's such a kitchen sink standard. The C++ community is so large and has so many stake-holders relying on diverse problem domains and programming paradigms that the standard has to permit the developer much greater control than higher level languages like Java.

In closing, to speak to the original poster's question, becoming proficient in C++ is in no way a career limiting move, and will definitely open up some opportunities. However, becoming an expert is a very deep rabbit hole to go down. Even a level of proficiency that will allow you to work on a large project will take some serious intellectual commitment. One way this is apparent is how the C++ community has its own large and distinct conceptual lexicon that for the most part has not worked its way into the general programming community. I personally found working on large C++ projects intellectually gratifying, so I would recommend helping out on the project for a year or so to start. That's enough time to get a very basic understanding of the language and see if it's something you really want to become an expert at. And even if you don't, you'll learn a lot.


This guy is giving you the best advice. They are considering the fact that you already know Objective-C.

One thing: I use Objective-C and I really like it. I don’t feel the same way about C++. If you feel the same way, honor the feeling. Still, I think you can learn C++ and have it be useful for you.

My best wishes!




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: