41

Currently I'm an IT student and I'm wondering what is still important in C++ today, what for is it used? I completed basic C++ course in my university but I can't imagine where can I use my knowledge and in which direction should I go learning C++.

In other words what should I learn to become a successful C++ programmer?

Currently I'm learning Java just because I don't see clearly in which area C++ could be useful today, but I clearly know which kind of work I'll be doing as a Java programmer. But I still hope that C++ isn't dead.

Thomas Owens
  • 79,623
  • 18
  • 192
  • 283
hades
  • 645
  • 1
  • 6
  • 5
  • 1
    @stign IMO it is likely that it will eventually die since there will likely come a time when all languages today are obsolete (probably due to massive changes in the hardware being used). – Kenneth Mar 23 '11 at 22:05
  • 17
    C++ is far from dead (I write new code in it every day), and if COBOL is any indication, I'll have work for many, many years to come. – Michael Kohne Mar 23 '11 at 22:26
  • http://www.lextrait.com/Vincent/implementations.html The role of C and C++ is "everything" – Mooing Duck Apr 09 '12 at 17:24
  • Nobody mentions it, but C++ is also used for game development on console. – lvictorino May 30 '12 at 05:16
  • 2
    This is my point of view. C++ is very useful in real time situation (and videogames). I also use C++ for desktop applications (don't forget about Qt) for performances reasons. – hosomaki Mar 23 '11 at 21:24
  • 1
    Recently I have watched some interesting videos on [Microsoft's channel 9](http://channel9.msdn.com/Tags/c++). Microsoft has spent millions on market research and based on its research it's talking about a C++ renaissance. See [this video](http://channel9.msdn.com/Shows/Going+Deep/Craig-Symonds-and-Mohsen-Agsen-C-Renaissance). – grokus Mar 24 '11 at 03:19
  • 2
    Take a look at The Programming Languages Beacon and make your own conclusion: http://www.lextrait.com/vincent/implementations.html – Nemanja Trifunovic Mar 23 '11 at 22:32
  • You should have a look at Herb Sutter talk. He is one of the big C++ guys. The video es also quite recent. http://channel9.msdn.com/posts/C-and-Beyond-2011-Herb-Sutter-Why-C – SystematicFrank Oct 31 '11 at 21:56
  • the C family of languages are the backbone of current coding (in my opinion). You want some driver code? C/C++ You want some low-level firmware? C/C++ You want some super-fast math code? C/C++ You want to write some libraries for games? C/C++. Don't get me wrong, other languages have their uses. You want portable code? Java You want a web app? Asp.Net/JavaScript/HTML/CSS. Languages are the tools that we use, and it's up to us to choose the tool that we feel best fits the current task. You can use a hammer as a drill, and a drill as a hammer - there are pros and cons to both. – Jamie Taylor May 30 '12 at 08:32
  • 1
    Related: http://programmers.stackexchange.com/q/113295/1512 – sbi Aug 20 '12 at 06:09
  • 1
    In what language do you guess was the browser written that you used to write that question? – Nils Apr 24 '14 at 14:58
  • Almost the same as in @Nils comment but anyway - the majority of the widely spread operating systems and system tools (windows, linux, osx, native mobile os, embedded os, basically the whole internet infrastructure and a lot more) are written in c/c++ and this won't change in the next (at least) 10 years or so. – keenthinker Apr 24 '14 at 16:16

3 Answers3

57

The killer feature of C++ is scope-bound resource management, SBRM (more commonly known as "RAII"). It is the only industrial programming language that is built around this concept. In C++, life times of all objects are exactly known, and (well-written) C++ programs guarantee that resources are acquired and released in fully deterministic manner. In comparison, garbage-collected or otherwise managed languages do not provide any such guarantees; in fact objects in those languages may persist after the end of their lifetime.

That is the reason why C++ is used in finance, video games, high-performance embedded and real-time systems, transportation, manufacture, and other industries where determinism and precision are important. There are no alternatives.

Granted, it was used for a lot more tasks than this, and those tasks are being lost to C# and Python and other more suitable languages, but that is not affecting its core niche.

Cubbi
  • 747
  • 6
  • 7
  • 2
    That's a nice, but not completely accurate answer. Python uses reference counting to collect garbage, and it can be turned off. Both have predictable performances (at least as good as the one due to the fragmentation `malloc` can't avoid) – Apalala Mar 23 '11 at 21:43
  • 20
    Anyone who uses malloc in C++ I'd like to hit their head with a hard object. Also, there a is a lesser known feature of the operator `new` in C++ called placement. It allows to reuse a currently occupied memory space. So if someone wanted to avoid (or minimize) fragmentation they can, in theory do that. And predictable is not the same deterministic. – Tamás Szelei Mar 23 '11 at 21:51
  • 4
    @Apalala C++ has reference counting too, but it is much worse than SBRM in terms of object lifetime management. I'm not *just* talking about hard-RT determinism, I'm talking about deterministic behavior of the object model. – Cubbi Mar 23 '11 at 22:06
  • 4
    When I learned C++, RAII was not particulary widely known; I learned new and delete and brain-based pointer management. So I don't think you can characterize it as being "built around the concept". The libraries and other support structures that are used today may have, but not the core language or syntax. – jprete Mar 23 '11 at 22:09
  • 7
    @jprete True that many of the C++'s strengths were discovered rather than designed. This post is about post-2005 language. – Cubbi Mar 23 '11 at 22:15
  • 1
    Yeah...when I heard about RAII, I thought to myself, "That's brilliant...too bad Java can't do it." Luckily we don't need it nearly as often, but it's a great way to get around what I always thought was C++'s biggest weakness. – jprete Mar 23 '11 at 22:18
  • 1
    FWIW, my understanding is that Perl5 is also reference counted. – Michael Kohne Mar 23 '11 at 22:24
  • While I agree this is one of the best things **about** C++ (+1), the question is asking for markets/where C++ is **used** -- and this really doesn't answer that question (-1). TOTAL: 0. – Billy ONeal Mar 24 '11 at 05:02
  • 2
    @Billy Since when did SE votes count become the indicator of the correct answer to the question? – Aditya P Mar 24 '11 at 06:00
  • 1
    @Billy ONeal: I only meant to say *why* it's used and not going away, in the markets mentioned in your answer. Dunno why people are voting me up. – Cubbi Mar 24 '11 at 09:59
  • @AdityaGameProgrammer: 1. err.. always? 2. I'm not talking about whether or not the answer is correct -- I'm talking about what question the answer answers (whcih seems to be different than the OP's) (Maybe we should call [Watson](http://www-03.ibm.com/innovation/us/watson/index.html) in on this one ;) ) – Billy ONeal Mar 24 '11 at 15:25
  • 1
    I still think that it is an excellent answer, but that it may be that you're confusing C++ with C. Operator `new` is almost always implemented with `malloc`, but the point about _placement_ is well made. – Apalala Mar 24 '11 at 17:26
  • 2
    C++ is not the only language using scope for releasing resources. `IDisposable` in .Net together with the `using` keywork in C# and `use` in F#. Combine that with `async` and you get scope-based resource and exception handling together with asynchronous programming. – Joh May 03 '11 at 07:24
  • 4
    @Job: While not completely wrong, it doesn't come near RAII in terms of usability. If you forget the using-statement in C#, you are on your own. You are also on your own when the lifetime of the disposable object shall be beyond the scope of a function. In summary, C#-using is more or less syntactic sugar for try/finally. – phresnel May 30 '11 at 13:06
  • 2
    You forgot D. It also has RAII, as well as scope statements. – dsimcha Oct 31 '11 at 23:09
  • 1
    D is hardly an industry standard language though – jk. Nov 01 '11 at 11:09
  • We use C++ in our project because we need to visualize and process images that are several hundred megabytes in size. Another project uses C#, but its performance is much much worse compared to the C++ project. – Giorgio May 30 '12 at 18:24
  • 5
    RAII *was* designed into C++. But most C++ programmers just kept on writing C, replacing malloc with new and free with delete. – kevin cline May 30 '12 at 20:53
  • "Anyone who uses malloc in C++ I'd like to hit their head with a hard object.": Anyone who wants to keep `malloc` in the C++ standard for backward compatibility with C should be hit even harder. – Giorgio Dec 23 '12 at 19:56
  • "But most C++ programmers just kept on writing C, replacing malloc with new and free with delete.": In my company we have about 50 C++ programmers and I never see malloc / free or new / delete in our code. I think that might have been true a few years ago but nowadays most programmers I know use smart pointers. – Giorgio Dec 23 '12 at 20:00
  • If anyone wants to see the popularity of C++, or any language, this is a good site to reference: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html. – Chris Jan 17 '14 at 11:35
  • The problem with C++ has nothing to do with C++ itself. Good C++ programmers are hard to find. Most companies/projects shun C++ because it's too often "C with classes". Upper management sees the frustration with it and believe it's subpar and replace it with C#/Java/etc. But really we're just breeding more idiots in the world by doing this. C++ can be as easy or as hard, as abstract or as complex as you need it to be. It's the most flexible language and can truly be used efficiently and reliably in any domain. – void.pointer Mar 25 '14 at 23:48
  • 1
    @RobertDailey I've been interviewing for years and found only a handful of people that understand C++.. but they are worth it. – Cubbi Mar 26 '14 at 01:51
  • C++ was not built around any concept other than to create an object oriented layer on top of C. In that regard it was wildly successful and led to the creation of later languages like Java and C#, which tried to improve upon C++ by removing weaknesses of C++ and added more modern niceties. C++ can do pretty much everything Java/C# can do and then some, however, it usually takes much longer to implement the majority of the C++ code compared to Java/C#. That's why C++ has lost a lot of ground because Java/C# really are a big productivity boost. But for many systems it is hard to beat C++. – Dunk Apr 24 '14 at 14:39
  • @Giorgio:It is far easier now to grasp OO and its good practices than back when C++ started becoming popular(early 90s). If u wanted to learn how to do something, u didn't have the internet, u had to use "gasp" books. IOW, most programmers had very minimal OO knowledge. So what ended up happening is most projects used C++ in very structured programming oriented ways(like simply replace malloc with new. They got the worst of both worlds(OO/Structured). You have directly benefited by these missteps because people were forced to come up with ways to avoid common problems (eg.smart pointers). – Dunk Apr 24 '14 at 15:00
  • @Robert:Good programmers are hard to find, not just good C++ programmers. There really isn't anything horribly wrong with C++, it has its areas where it shines, but at its core it is a low level language. Being a low level language, it generally means the programmer has to worry about more of the details. Having to worry about more of the details means it takes more time to develop in C++ versus a comparatively higher level language. I was all about C++ eons ago but after working a couple of projects in Java/C# it became obvious that it takes longer in C++. Is that a problem with C++? IDK – Dunk Apr 24 '14 at 15:10
40

There are a few markets for C and C++ (to my albeit limited understanding)

  1. Existing code. C and C++ have some of the largest existing codebases around. Code of this size can't simply be thrown out just because the "next hot new language" has come around. C bindings are pretty much the standard of inter-langauge interaction on most platforms, so being able to author (at the very least) wrapper libraries in C or C++ is useful.
  2. High performance applications (e.g. high frequency finance). C and C++ still achieve better overall performance than most other programming languages. Most importantly in C++, one often builds abstractions with compiler-only things like templates, which moves computation from runtime to compile time (making your overall app faster).
  3. (Similar to 2) Low latency applications. Languages which run on e.g. the CLR or the JVM can often be nearly as fast as C++ depending on the application, but one still needs to load the CLR or JVM themselves into memory before your program can execute. If you have hard startup requirements this is important. EDIT FROM COMMENT: For that matter, hard latency requirements of any description are of note here. Languages which run on virtual machines rarely offer hard time limits because running of e.g. garbage collection is not a deterministic process.
  4. Embedded systems. Some embedded systems have the hardware to run e.g. the JVM (Google's Android (Okay, it's not really the JVM, but it's close), RIM's Blackberry) or the CLR (Windows Phone), but most embedded systems don't have the power to run languages which require more runtime support than that required for C or C++ (which is next to no runtime support at all).
  5. Deployment constrained applications. Sometimes requiring installation of the JVM or CLR is massive overkill if your entire program is only a few hundred KB. (E.g. most of the programs I work on must be deployed as a single .EXE file without any kind of installer or anything like that; for this there are no alternatives)
Billy ONeal
  • 8,073
  • 6
  • 43
  • 57
  • 2
    Startup latency isn't the only kind of latency to be concerned with: Hard realtime requirements can be a much bigger dealbreaker. – greyfade Mar 23 '11 at 23:02
  • 1
    Add in anything where you don't want to be locked into a particular maker (C# or Objective-C) or don't want your language to disappear into a bunch of lawsuits (Java) – Martin Beckett Mar 24 '11 at 04:45
  • @greyfade: That's kind of what I meant by (2), but I agree that's not clear. Edited. @Martin: While I think that's a good strength for C++, I don't think it answers the question -- which is in what markets is C++ commonly used. Also I don't think I'd call C# locked to a particular maker when a BSD (OOPS: It's LGPL) licensed version of the CLR exists (mono). – Billy ONeal Mar 24 '11 at 05:05
  • 1
    Also 5. Operating systems and core framework. You can do a lot in a virtual machine, but the virtual machine still has to be implemented in C and/or C++. – Jan Hudec Nov 01 '11 at 12:49
  • @Jan: I would argue that's false. Of course, you would have to have a restricted subset of, say, C# or Java, which didn't follow normal GC semantics. Or you could use any other language that results in native code, such as FORTRAN, assembly, Go, etc. – Billy ONeal Nov 01 '11 at 13:07
  • @BillyONeal: Any such subset or language would not have issues 2-4 either. Alas nobody tried to define such modification of C# or Java (for Java it's extremely big problem because it does not have user-defined value types) and e.g. FORTRAN existed before C and yet nobody ever wrote an operating system in it. Obviously assembly is what was used before C (and you always need a little bit of assembly even when using C for the rest), but that's not a structured programming language. – Jan Hudec Nov 01 '11 at 17:07
  • 1
    @Jan: Yes it would. Things like reflection and friends would trigger problems 2-4. The only subset you would really need to write the garbage collector would be some object which represents physical memory. – Billy ONeal Nov 01 '11 at 17:14
3

C++ is still very useful and by no means dead. If you want to read a serious comparison between some different programming languages check the paper An empirical comparison of C, C++, Java, Perl, Python, Rexx, and Tcl. It's not the most updated but I believe that most things still hold.

sakisk
  • 3,377
  • 2
  • 24
  • 24