tags:

views:

1657

answers:

23

Everyone has been telling me to learn C++. Without bashing languages right and left, can someone please state some relevant reasons as to why I should learn C++ today?

Note that in no way am I saying anything harsh about C++. I just want to know why I should master it as a programmer instead of the other powerful languages out there.

A: 

Many of the newer languages such as Java and C# have roots in C++. By learning C++ you will get some hands on experience with many concepts that are abstracted in the newer languages. It will make you appreciate the newer languages much more. Things such as memory management are very trivial in Java/C#, but take a lot of thought and patience to correctly implement in C++.

Mr. Will
I would respectfully dispute whether learning C++ will help in any way make you a better C# developer. I came from a C++/VB background prior to the release of .Net and I find that C# is different enough in it's philosophy as to render prior C++ knowledge unnecessary. That is not to say that it doesn't help, it does. But coming directly into C# without prior C++ experience will not hinder you at all.
Eric
I did not say that it would make you a better C# developer. All I was stating is that after toiling around in C++ having to do things like memory management yourself, you will see how far languages have come.I agree that having a background in C++ will not make you a better C# developer. I actually believe its better to just learn the programming fundamentals as you can apply those to any language.
Mr. Will
Perhaps I misunderstood your statement. My bad!;)
Eric
No worries. It at least stirred up some nice banter haha.
Mr. Will
+6  A: 

For one reason, it's in extremely wide use in the programming world. For another, it is the intellectual predecessor of two other major languages out there, Java and C#. As such, C++ and techniques directly derived from C++ are in use in a very high proportion of professional projects in the Software Engineering world (I don't have exact nubmers, but I'd say higher than 50%).

McWafflestix
Very little in Java and C# is derived from C++, other than a bit of syntax. Mostly, those languages are inspired by what's more accurately called C with Classes. Both languages are based on what C++ was in the mid-90's. Today's C++ has almost nothing in common with that.
jalf
@jalf: are you sure you're not conflating "language syntax" with "typical usage"?
McWafflestix
Pretty sure, yes. C# and Java have inherited a bit of syntax from C++, and nothing else. They certainly have not inherited "typical usage".
jalf
@jalf: yes, my point was that "typical usage" of C++ has drifted away from the original language syntax, which is what Java and C# gained from C++. Things like template libraries which are in wide use in C++ nowadays are a modern drift, that really is more like an extension to the language (except they're not). The typical usage of those libraries is, in my opinion, what makes modern C++ so different from the "original" form that C# and Java derived from.
McWafflestix
+14  A: 

This has to be a duplicate of something...

You should learn C++ because it's very commonly used, it's efficient, it's the basis of many other languages in common use, and because half-knowing C++ is dangerous.

Dan Olson
I think even more than half-knowledge can be dangerous as hell, as I find that there's a lot of terrible code written by people who consider themselves "experts" or "nearly experts" in C++...
McWafflestix
It is not "very commonly used". It is commonly used in some fields, and hardly at all in others. Plenty of programmers never need to even look at C++ code.
jalf
@jalf - speaking in terms of relative popularity of use, C++ is a "very commonly used" language, along with C, Java, and C#. #3 on TIOBE this month.
Ben Collins
@McWafflestix, surely that's more of a comment about the programmers you're referring to than about C++. It doesn't make any sense to blame cars for bad drivers, for instance, does it?
Dan Olson
@DanOlson: yes, of course it's a comment about the programmers; I wasn't particularly "blaming" anyone, but was leaving a comment in reference to the answer. Did my comment come off particularly more abrasive to the language (as opposed to the programmers) than the original answer?
McWafflestix
@McWafflestix, I just didn't follow the logic, which I interpreted to be "experienced C++ programmers are occasionally bad programmers, therefore the fact that half-knowing C++ is dangerous isn't a valid reason to learn it well". I'm entirely open to criticism on that point of my answer, but I don't think your argument as I've interpreted it follows logically.
Dan Olson
The last part is the most funny
Ismail
+4  A: 

Answers to this question contain a lot of reasons: Which sector of software industry uses c++

Pukku
A: 

It depends on what your'e planning on doing with it.

Languages are tools in a tool box. Pick the right one for the job.

  • Windows development: C#
  • UNIX development: C++ or Java
  • OS X development: Objective C or REAL Basic

In the end it's a judgement call. I'm sure someone will dispute the preceding list. It's an opinion, not gospel.

:)

Eric
C++ is still valid for Windows development depending on what you're doing.
Frank Schwieterman
While that is certainly true, I think that the bulk of Windows development would not necessitate using C++. C# has a much shorter development cycle and is far easier to maintain, so corporate development (the largest community of Windows developers) is using C# as the primary tool of choice.
Eric
+9  A: 

Learn C first. Then learn C++ to appreciate the power. Then learn a higher level language. You may even want to learn a very small amount of assembler before you start with C. Yes, this sounds like a lot of work, but... well it is a lot of work. Fortunately, it's enjoyable work. :) The point is not to become an expert in assembly, C, and C++. The point is to understand how the nice shiny languages do things internally, which will definitely make you a better developer.

Also see http://stackoverflow.com/questions/296/should-i-learn-c

dss539
There is no advantage to learning C first. C++ done properly is such a different language that most of C is irrelevant. Though a lot of people still write C with Classes (This being distinct from C++)
Martin York
"C++ done properly is such a different language" therein lies the advantage! They are different languages with different levels of abstraction. That's my whole point. I did not recommend learning C first to give him a "leg up" on learning C++.
dss539
I think you should learn higher level programming languages before you learn more lower level ones such as C. First you should be able to think in an abstract way about your programs, to see them as mathematical entities, then you can go play with pointer arithmetic or registers.
Artefacto
Artefacto, I think you might be right. Many developers get mired in low level details and can never move up. However, many developers also get mired in frameworks and never bother to understand the lower levels either. Maybe the choice of learning low->high or high->low depends on the individual.
dss539
+24  A: 

Should I learn diving or Chinese?

It depends. What do you need? Do you work in a company that uses C++? Do you work in an industry where C++ is prevalent? Do you plan to work in such a place? Are you a programmer? Do you want to do programming?

The vast majority of people on this planet do not learn C++, and they manage to live quite well despite it. Most people don't learn any programming language. They don't need it.

Do you need it? If so, learn it.

If you're going to do any C++ programming, learning C++ will be a very good idea. If not, other languages may be more relevant.

But learning new languages will always be a good thing and make you a better programmer. If you have the option, you should always learn new languages.

jalf
@jalf: Note that he did not really ask *whether* he should learn the language or not, but rather for reasons *why* one should perhaps learn it. While I fully agree with what you write, I don't think you actually answer the question.
Pukku
Well, in that case the answer is "because you'll then be able to code in C++". ;)
jalf
Fair enough! :)
Pukku
I object to your 3rd paragraph. Most people who don't learn programming languages do not live quite well. Even if they don't "need" to write programs, the logical thinking it imparts upon your mind is invaluable across nearly every field. I'd say the benefits can be compared to (but are distinct from) the benefits of learning a foreign spoken language, despite never planning on travelling to that country.
rmeador
So their lives suck because they can't program? A lot of people would disagree.
jalf
@rmeador: That is just ridiculous. You think that not knowing how to program has a measurable negative effect on someone's life? C'mon.
Ed Swangren
That's just ridiculous. How often do you meet a Chinese diver?
Mike Robinson
+1, great answer
Darin Dimitrov
A: 

I think you need to define "learn it." Does that mean a tutorial and you're done? Does it mean build an application (what kind?)? Those same people telling you you must learn C++ use it in different applications. The next step is "You must learn to make this kind of application..."

I think you may just feel incomplete without it and are giving into hype about "real" programmers.

johnny
A: 

By learning a lower-level language such as C++ you will learn basic concepts such as:

  • Memory Management
  • Pointers
  • Experience coding without "rich" built-in libraries (compared to: Java API, .NET Framework)

Once you have solid experience with a lower level language, you will have a better understanding of how higher-level platforms work "under-the-hood". Over the long term this will help make you a better developer in Ruby, Python, Java, etc...

Justin Ethier
"C++ is also object-oriented" please be careful when telling that to a neophyte programmer. That often leads them to think "I made a class, thus my design is OO!"
dss539
Which also happens in Java, although they think "This program was written in Java, therefore it's OO!". However, C++ is particularly dangerous for an overconfident know-it-all neophyte.
David Thornley
C++ is OO in the sense of "OO, it crashed again!"
Daniel Daranas
+11  A: 

I think there are several reasons to get at least passingly familiar with C++ even if you plan to use higher level languages as your tool of choice. Here are a few:

  • It's like learning Latin to understand English better. A lot of languages were modeled on the syntax and constructs, for example C#, Java, JavaScript, etc. Picking up C++ or at least C will give you a head start by teaching you the common denominator between all those languages.

  • Understanding the things that are abstracted away from you in other languages (pointers, basic data structures, garbage collection) theoretically makes you a better programmer even if you don't directly tinker in the details.

  • It doesn't happen every day, but one day you are going to need to connect directly to a C++ program API from your high level language. It will help if you have at least a passable knowledge of C++ when this happens.

  • C++ on your resume can often lead to Salary++. It is just respected as more of a hardcore language.

  • I often see C++ used as a common language between programmers who work in different languages, and in programming books that are trying to be language agnostic (Code Complete). Knowing C++ opens access to a lot more learning material.

BTW: I wrote a quick blog article in response to this question that goes into a little more detail.

JohnFx
+1 for "It's like learning Latin to understand English better", although C++'s status today is quite different than that of Latin :)
Dunya Degirmenci
Granted. I was a bit worried that someone would take that analagy too far and assume I was calling C++ a dead language, which it is not.It's a DYING language. J/K!!
JohnFx
+11  A: 

Some other reasons here:

  • Nearly all of the books in science and technology have their code samples written in C/C++.
  • C/C++ compilers are known to produce more efficient machine code than any other compilers (with fortran perhaps been the exception).
  • There are billions of lines of code already written in C++. Your possibilities for code reuse are huge!
  • Lots of books, forums, online content about the language.
  • Well defined ISO standard that is updated by a group of experts from time to time. (It's not a "frozen" language).
  • Supported on most platforms, from microcontrollers (actually C language) to cellphones.
  • Virtually all of the operative systems are coded in C so you have no choice if you want to be an OS developer.
  • Since there are several "modern" languages that have a syntax similar to C++ syntax, by learning C++ you will be able to understand code written in those languages (E.g. PHP, Java, C#, Javascript/Actionscript).

If you want to be a competent programmer you should not only learn C++, but also take a look at some other languages that will extend your horizons: python, lisp, prolog, assembly, etc.

Sergio
"Nearly all of the books in science and technology have their code samples written in C/C++." - not true in my experience. Citations for that, please. The (admittedly old) mechanical engineering books that I have use Fortran. I would say that Python would also be a commonly used scientific computing language.
duffymo
I have almost never seen an sci-tech textbook showing python code (unfortunately). Yes, fortran was very popular back in the 70's but not anymore. There are many areas in which C++ almost absolutely reigns (networking, telecommunications, OS design).
Sergio
@duffymo, well that is right, but only for "scientific" stuff ;)
daemonfire300
+11  A: 

I'll take a contrary position. Don't learn C++, it's a waste of time. Unless you have an immediate and pressing need for it, your time would be better spent elsewhere. Better language choices for long range career plans may include Hindi, Urdu, Chinese, or Russian.

The sorry fact is that there is more in the world to learn than you can learn and soon or later you will need to choose your areas of ignorance. At this point C++ can be safely ignored (again, depending on immediate needs). Instead of building up your tool set why not build something with it? That's an education in itself.

Glenn
+1, "Don't learn C++, it's a waste of time." + "Better language choices for long range career plans may include Hindi, Urdu, Chinese, or Russian."
daemonfire300
1++ for comparing C++ and Hindi. Yay!
Bart J
+2  A: 

The reason most people say C++ is because that's whats generally been the most common in colleges. The best advice I can give is not to learn one language but learn multiple languages at once. If you are doing really beginner stuff C++ is fine but essentially not very different conceptually from other languages out there. I am by no means a "master programmer", but I would think a master wouldn't pigeon-hole themselves by limitting their knowledge to one language.

DJ
pigeon holes are for pigeons
dss539
I think C++ is very different from most other languages. STL is unique.
kotlinski
I think Java is far more common in colleges. And yeah, C++ differs from most languages conceptually. Wheres the generic programming paradigm in C, C# or Java? That said, I agree with your point. If you already know one of these languages, going for a functional one next will probably be more enlightening.
jalf
+4  A: 

You should learn it if you are interested in real-time, high-performance computing. C++ is much more expressive than C, and still more effective than all the other languages. It's the right language if you want to maximize the use of available resources.

Given the task, I also think it's a lot more fun than e.g. Java or Objective-C :) It takes a lot to get good at it, but the reward is great. It's an expressive language, and the programmer is given great control over what happens.

kotlinski
A: 

Another reason to learn it is to understand why so many people love / hate it. Rather than take their word for it, learn it yourself to better understand the values and issues these folks have with the language. It certainly has its fans and naysayers.

Personally, having used it, it has some really nice aspects for the work I do, but having left it behind, I don't miss it.

Will Hartung
A: 

I'd say learn C++ because "it's a better C". C is the language of systems programming, so if you plan to do it you'll want to know C/C++.

Peter Norvig's brilliant "Teach Yourself Programming In Ten Years" is pertinent regardless of which way you decide to go.

On second thought, maybe the best reason to learn it is to persuade those people to stop telling you what to do. 8)

duffymo
+2  A: 

It depends on how you define "learning a language".

Learning C++ syntax is a basic matter of writing a handful of practice applications and reading blogs and forums (and definitely Stack Overflow (: ).

Then you get to learn other structures like pointers, classes... writing them is a step forward from basic syntax.

Then comes the data structures and I believe that is where the hardcoreness of C++ comes in: the implementation in code is usually similar to how you'd write an algorithm in common pseudocode. The thing is, YOU will usually have to implement them, making it a must for you to know almost every detail of an abstract data structure - contrary to how things work in languages with the structures like hashtables, linkedlists etc. built in.

Being proficient in a high level language may make you a programmer, but "knowing" C++ in that aspect will make you conscious of what you have been doing in all the programs you have been coding. There may be people who will put forward the argument "if you want to know what you are doing, learn assembly" - I don't know assembly (yet), so I won't be able to reply, but I'd still say that C++ is somewhat more "learnable".

And then there are different libraries, all with their pros and cons, all being constantly developed further... so "learning C++" is not really a process you can ever reach the end of :)

Dunya Degirmenci
+1 You make some excellent points.
dss539
A: 

Because that would would raise your quality as a programmer (in case that bothers you).

Another thing to mention - more recent languages are more abstract. Older languages talks closer to language CPU uses (for me C++ seems like a history (no offense to anyone)).

For example - i started to code in ASP.NET. Learning about HTTP and HTML gave me an insight what ASP.NET does behind the scenes, therefore - i`m able to control it better.

Conclusion - you need to understand abstraction from what everything is made from.
And don`t forget that C++ is abstraction, built from something else too.

Arnis L.
+3  A: 

For any reasonably experienced software developer, learning a new statically typed object-oriented language should be a piece of cake. The main difficulty in learning a new language is learning the main API of the programming environment that you're in. For C++ that is really easy, the STL is pretty small, and as far as I know C++ doesn't really involve any other standard libraries.

Some of the most important reasons to learn C++ are:

  • Understanding memory management and pointer usage.
  • Inventing your own class hierarchy instead of relying on pre-packaged libraries from your language vendor.
  • Learning how to use templates and generic programming principles.

I think that last one is particularly important. No other language (at least the languages that I've used) does generic programming quite like C++. Alexandrescu is definitely a worthwhile book to pick up if you want to really understand the power of C++.

Peter Kovacs
A: 

You should not care about C++. Try something newer such as C#, ruby, python and best, care about design pattern and work methodology. That's take you to the sky!!

Eduardo Xavier
A: 

I would say the primary benefit is learning memory management and pointers. Keep in mind there are many advantages to knowing how memory is handled, no matter what language (even GC equipped languages). You simply don't get that experience with most other mainstream languages.

Tom Bennett
A: 

If you have a serious intention of becoming a high quality professional developer, rather than just being a hobbyist, web or junior developer, then I would suggest learning C++.

An analogy: if you build a house without good, strong foundations, it may stand for a year, or two years, but at some point it will fall over. If, however, you build a house with decent foundations, even though you may never look at those foundations again in your lifetime, you can guarantee your house is structurally sound and can go about your business without worrying about it falling down around you. Developers who start out with a high level language like C# or Java are building their house without foundations.

flesh
A: 

Opinion: You don't have to know C++ to be a programmer.

However, if you do not understand basic concepts and design considerations of C++, you should not be programming.

Examples are pointers, how highlevel and low level abstractions link, memory management, stack, temporaries, etc. Without these, you will not be able to understand what really happens under the hood in a complex program, regardless of the language.

Likewise, you don't have to know trigonometry to do database design. But you will never find a good database designer who cannot prove cos(b-a)=cosb*cosa-sinb*sina in 10 minutes. Be sure that Dennis Ritchie knew complex calculus when he designed C, and every good optometrist knows what's light polarization, even if he doesn't exactly use it.

Pavel Radzivilovsky