I've been self-learning C++ for about 4 months now. I'm enjoying it, and I think I'm doing quite well. However, an answer to a question of mine got me thinking that I might be setting myself up for a fall.

So, what do people here think about C++ as a first language to learn? And is it worth me just carrying on now that I've made a good start?

+1  A: 

For me C++ was my first language too and I guess it was a good choice. You learn all the basic principles of OOP and will understand the logic structure of programming. But of course it depends on what you wanna do with it.

But I'm pretty sure if you switch to rails to do all the fancy web-apps you'll become a much better developper than anyone who started with PHP or - worst case scenario - Rails.

So go for it!

+3  A: 

I think that C++ might not be the most user-friendly language to develop in for a first timer, but it is also not going to hold your hand and necessarily lead you towards too many bad habits (I didn't say any, just not too many).

C++ was the introductory language that my university's programming courses were based in and that's where we learned all the basics and about data structures and algorithms before branching out into the languages of our choice.

+4  A: 

C++ as a first language can be OK if you have a good teacher. But it's a pretty high wall to scale for the first time, but once you scale that wall, other similar languages come very easy.

So yes, carry on.

Ólafur Waage
+1  A: 

C++ is a tough first language to learn, but it's not impossible, and you will learn alot from it. The key to it, like anything else, is to not give up if you don't understand something. Ask questions, and read if something isn't working. Eventually you'll find an answer. I think the best quote I can give you about your task comes from Randy Pausch:

“Brick walls are there for a reason. The brick walls are not there to keep us out. The brick walls are there to show you how badly we want something. Because the brick walls are there to stop the people who don’t want something bad enough. They are there to keep out the other people.”

I love the quote! I've hit brick walls before and despaired, but I'll look at them differently from now on :)
great quote, thanks
The quote is from The Last Lecture. I'll go find a link and add it. The whole thing is a must-watch.
+3  A: 

Carry on. C++ is still widely used and THE language for certain kind of work. So it depends on what you want to do - systems programming is done in C++ or C, business and web apps tend to be done in other things.

I do strongly recommend that you explore other languages as well. Python is my second language, for example; it may give you new insights about object-oriented and functional programming and make you a better C++ programmer (and a better programmer overall).

I believe being exposed to as many languages (and, more importantly, to many different programming paradigms) will make you a better programmer overall. Take a look at Haskell, Prolog, Lisp, and an Assembler variant, at least.

+3  A: 

For me learning C++ is mostly about learning how NOT to shoot yourself in the foot. It can be a painful exercise as with C++ there is always another edge case that will make the gun go off as it's pointing at your hoof.

The up shot is, if you manage to finish the exercise, you'll be a better developer for it, and you will be able to spot future foot shooting opportunities before they happen, in what ever languages you end up using.

Also, when some third part library shoots it's self in the foot, you'll be better positioned to grok what went wrong than others that haven't repeatedly shot their feet for months on end.

I'd say stick with C++, it's not a waste of time, even if you never write a single line of production C++ code.

Hope this helps :)


Binary Worrier
I would strongly recommend Scott Myers "Effective C++" books for C++ developers at ANY level
Binary Worrier

You will make mistakes in any language that you begin to learn. Some languages may have less pitfalls to watch out for, some may have quite a few. Whatever be the language, you are sure to invent your own pitfalls. Now that you have spent about 4 months, I'd suggest you carry on. A switch now may make things more difficult given the fact now you have two things to accomplish:

  • Unlearn C++
  • Learn language X from scratch
There is absolutely no reason to "Unlearn" any language. Quite the opposite. You will always benefit from knowing the nuances and benefits of various different languages.
Robin Day
Try learning C from C++.
+5  A: 

any language is a good first language (within reason, not something like lolcode)

once you get the hang of how it works, it becomes easier to branch out to other languages.

+1 even though I disagree with one part. lolcode rocks!
Robin Day
yes it rocks, but it isn't a good first language ;)
CAN HAS makes so much more sense than #include though!
Yeah, but the arithmetic operators are awkward.
David Thornley

I'm not a fan of C++, mostly because of its syntax. I find it horrible and very problematic in use, and I'm not alone with this opinion. Perhaps, if you spend enough amount of time to master it, it will be no problem anymore, but I prefer to choose much more elegant Java that lets me creating desktop apps faster and making them more portable, and pure C to deal with system- or performance-oriented jobs.

BZZZZT. Java might beat C++ in many aspects (portability, or ease-of-coding-your-first-GUI), but certainly *not* clarity of syntax.
How can you complain about C++ syntax, and yet praise Java. Their syntaxes are almost identical.
in two words C++ is a mess !!
Stroustrup had an excuse: he was deliberately keeping C compatibility. What's Java's excuse?
David Thornley
Yeah, I was ready to vote you up until I got to the Java part. Since you didn't have a good alternative, I'd suggest Ada.
+45  A: 

I don't understand why people still confuse "language" with "library". (Referring to the linked answer.) So what if C++ doesn't have a "native" concept of audio? There are lots of libraries out there, which you can readily use with C++, and which are probably better suited to your specific needs than any "catch-all" "standard-library" audio processing API could be.


C++ is a difficult language. There are others that are easier to learn. I would never argue about that.

But C++ is easily one of the most powerful languages around. It can be highly efficient, and highly elegant, at once. Of course, nothing keeps you from making a fine big mess of everything, either.

If I recommend C++ as a first programming language? Actually, I don't know any better. Others might protect you from making mistakes, and make initial success (e.g. your first GUI application) easier. But if you build on a foundation of C++, you will always be on a secure footing. You might never have to chose another language at all, actually. But if you want / have to, you will find it ridiculously easy.

An experienced C++ coder can do e.g. Java at full speed in a matter of weeks. The other way round? Much, much more difficult.

Very much agree. Once you know C++, all other languages are easy by comparison. At least until you venture into other paradigms like Lisp, Haskell, or Prolog.
Well, I always wanted to venture there, simply for the learning experience, but for the heck of it I could never figure out what I'd actually *need* them for. :-D
+1.I agree with many points apart from where you say it's the best first programming language. I think making quick progress (e.g. that first GUI app) is important for students, and they can decide if they like programming without being overwhelmed by language details.
Personally, I think no-one should code a GUI app before he understands the concept of action handlers. And that one is difficult to do without a secure knowledge of OOP, and impossible to do *well* without lots of experience. Why toss people into deep water before they can swim?
+1, even though I'm a wholehearted C# supporter! However, I would say that C# can be just as powerful and elegant as C++, if it is an option on your OS.
John Gietzen
When I hear "power" I think of what it can do, and seeing as anything that can be done in C# can be done in C++, but not the other way around, I'd say C++ is the more powerful language.That said I still enjoy C#.
While the distinction between language and library is important, a language with easily accessible 3rd party libraries (Perl/CPAN, Python/PyPI) or large standard library (Java, C#) does have benefits, and C++ is lacking coherency in 3rd party libraries since they are almost all developed out-of-sync with each other. This is why you see huge wheel-reinventing frameworks in languages like C++. (And this is coming from someone that prefers C++ over many other languages, but I also love Python.)
Roger Pate
Additionally, a large standard library has disadvantages, when you start deprecating and replacing parts of it, since you can never really remove anything.
Roger Pate
+1 - And not only to make it 42
+4  A: 

Personally, I think everybody should start with BASIC. No, really I do. At least first the first 2 weeks to 1 month. It's great for high school courses. It's simple enough that you can focus on very simple things like using variables, looping structures, conditionals, and calling subroutines without having to worry about frameworks, objects, and pointers. However, if you've already gotten past all that simple stuff, there's no reason you can't just keep on going with C++. It's a great language. And very useful. I think that people who have never programmed in C/C++ are really missing out on some fundamental things you should know about how things work on a lower level.

You've made the point I wanted to make....BASIC first to learn "what programming is", "C++" to learn how to program.
Richard Corden
Good idea. I agree. When I was in elementary school I learned qbasic. Learning program structure as a kid helped immensely when I moved to Visual Basic and then C++ in high school.
There are several good learning languages, and I personally dislike Basic. I'd suggest Python to learn the simple stuff with.
David Thornley
Dijkstra disagreed with you rather strongly: "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."
And yet somehow, we seem to have quite a few good programmers who's first experience programming was with basic.
+7  A: 

You should ignore advice "learn C first", because C is a subset but not a proper subset.

C++ is arguably the most complex (and powerful) mainstream language at the moment. Learning it as a first language might be a little harder but not all that much. You can't learn any language all-at-once.

Having said that, you probably should look around and learn to understand and use one or more other languages, it gives you a much better perspective.

Henk Holterman
Why was this downvoted?
Konrad Rudolph
Maybe because he states a clear error in the first sentence. C is a perfectly fine and useful subset.
I didn't say C isn't usable, just that it is not a proper subset as in set theory.
Henk Holterman
+24  A: 

Let me put it this way:

I took and passed with a 94%, the Sun Java Certification without ever having compiled a line of Java (that was nine years ago). I was able to do this, because I knew C++ very well.

On my first professional job, I was hired as a tester. On my second day, I was told I could program instead of test, if I learned enough PowerBuilder to be useful -- in two weeks. Because I knew C++ so well, PowerBuilder was easy.

C++ is hard, but if you learn it well -- read Stroustrup's The C++ Programming Language, do the exercises too, read his Design and Evolution of C++, read the C++ Faq and the Meyers books and Herb Sutter's books, read comp.lang.c++.moderated, read Coplien's Advanced C++ Programming Styles and Idioms no matter what OO language you want to code in -- if you learn it well, every other OO language is easy.

Learning C++ is excellent preparation for learning to code. (And you'll become a fair C programmer too, but read K&R to get to be a good C programmer.)

Oh. And C++ is really fun to program in, much less verbose than Java, and much more flexible. You're really in charge, not the IDE or the language. You can shoot off your own foot, but you'll be in charge of doing it. And read Alexandrescu's book once you know templates, it'll amaze and dumbfound and delight you.

C++ is fun. Read the "Curiously Recurring Template Pattern": it looks like this

template< class  T> struct base {};

struct derived: base< derived > {};

Yeah, you got that right: it's a class that derives from a base that's templated on the deriving class. Now that sounds just obscure and silly, but there are many good uses for it, and just the other day I was beating my head because you can't do this in Java (because Java uses type erase, not templates, for generics), but if I could have used it, I could have saved lots and lots of code repeated in lots of classes.

There's so much more in C++, and if you limit yourself to Java or .Net, you'll never discover it.

+1 for the fabulous gush :) I loved learning C++ and was lucky enough to master aspects of it when working with it for 5 years or so. It's still my "favourite" language even though I hardly use it anymore.
Binary Worrier
"if you learn it well, every other OO language is easy." I beg to differ. What you mean is "every other C++-style OO language is easy".
+1 for fun and templates!
ilya n.
+2  A: 

C++ was the first proper language I learnt, and it set me in good stead for learning other languages (C# mainly).

Among other things, it gave me a good grounding in object orientation, which really, really helped, when working with Siebel and with C#.


Nick Haslam
+2  A: 

C++ is good choice for a first language. Particularly if you're four months and making good progress I would urge you to not change now. C++ is hard, but it's a good language to learn because it doesn't hide anything from you and because so many other languages use a similar syntax. Make sure you give yourself plenty of time to understand that syntax so you can easily spot the differences (which can be quite subtle) when you start learning other languages.

Finally, I would caution you to make sure you're concentrating more on programming concepts than on language concepts. With every new C++ syntax feature you learn, ask yourself "What problem does this solve?" It's those solutions to problems that are far more important than the particular implementation in C++ or any other language.

Bill the Lizard
+2  A: 

If you were just about to start out I wouldn't recommend C++ as a first language, because the first thing you need to understand as a programmer are the programming concepts, and in C++ you'll spend a lot of time wrangling with the syntax.

But since you're four months in and enjoying it then it sounds like you are doing okay, so I'd say carry on. But round it out with some more general reading. Something like Structure and Intepretation of Computer Programs. It will teach you things that just ploughing throw in C++ won't occur. Things that will make your C++ programs better (and make you better in other languages as well).

Dave Jennings
+11  A: 

C++ isn't an easy language to learn as noted by everyone else, but there are a few reasons that it makes a decent place to start:

  • it doesn't tie you to a specific programming paradigm (e.g., Java and OOP) so you can experiment with different techniques easily
  • C++ doesn't have the bells and whistles so you can concentrate on making the building blocks if you want to know how they are built
  • since it is a language and not a platform, you can choose the library or libraries that best fit the task at hand or your chosen programming style (e.g., choosing something like Poco for a Javaesque feel, ACE for the gritty early style OO, etc.)
  • it is a general purpose programming language, not a platform (had to say that twice)

The trick is learning it carefully and correctly the first time. I know that I, like many others, have struggled with it by learning it as "C + objects" before really understanding it. It is a hard language to learn. I would recommend looking for an experienced C++ mentor to attach yourself to as well as reading a lot of the "highly recommended" books on how to and how not to write C++. Avoid learning bad habits up front.

For a starting reading list in no particular order:

  • "Accelerated C++" by Koenig and Moo
  • "Effective C++/STL" by Scott Meyers
  • "Object-Oriented Software Construction" by Bertrand Meyer
  • "Expert C Programming" by Peter van der Linden
  • "STL Tutorial and Reference Guide" by Musser, Derge, and Saini
  • "The C++ Standard Library" by Josuttis
Stroustrup's "Programming: Principles and Practice using C++" is also good. I question the van der Linden book: while it's an excellent book to have around programming C, I don't think it's useful for C++.
David Thornley
I actually think that van der Linden's book is very useful for C++ programmers. It contains some of the best descriptions of how pointers and memory management really work. Basically, it contains all of the nitty gritty stuff that C++ is supposed to hide but never can ;)
+8  A: 

Lots of support for c++ here, but I have to disagree. Every language has it's plusses and minuses (some achieve a better balance than others, of course).

That being said, for a first language, I'm convinced most people will learn how to program more effectively with a language that a) doesn't have an edit-compile-run cycle (which is inherently slower for you as the programmer b) has garbage collection c) has good runtime introspection. Best of if there is an interactive evaluator as well, to mess about with.

Development (if not runtime) is almost invariably faster in such languages, there are fewer things to trip you up, and there are better tools to help figure what went wrong when it did.

Which isn't to say learning the vagaries of memory management in a language like c++ isn't something worth doing, etc., etc., it just isn't the place you really want to start.

Another issue with c++ is that for all its practicality the sheer size of it added to the fact it has incompatible parts that can lead to subtle issues best avoided as a beginner.

edited: John D brings up the point in a comment that some people who learn first on a GC'd language (which is by no means limited to "scripting" languages) never learn pointers later. This is a red herring, though. Some people fail to learn all sorts of things, for all sorts of reasons. I maintain that worrying about pointers is a distraction when you're learning the basics. At some point you may well need to learn about manual memory management, but it's not fundamentally important to do this at first. Or more accurately, the gains made by avoiding this are more important than the costs.

Let me be clear though, I'm not saying that c++ is an inferior choice for a first language because it lacks garbage collection. That's just one of many issues that get in the way of learning the fundamentals of programming well. The real problem is that it is a large complicated language, with quirks all over the place and even internal inconsistencies (e.g. pointers and exceptions don't play well together). Of course all of this can be managed properly and you can learn good practice to keep from getting in trouble.

However, none of this will make much sense to a real neophyte at first. So some of learning it will end up being "do it this way, not that way". "why?" "because I said so --- you won't understand the details yet". Hardly an auspicious start.

The bigges gains for learning a first language though are probably in avoiding a edit-compile-run cycle (of any kind) and having good introspection.

Disagree. For example many programmers I know who learned to program in a GC-ed language then come to C++ and never really "get" pointers, and up believing that pointers aren't really a "part" of programming and disregard them as something they never have to figure out. Script kiddies forever.
John Dibling
I started to agree, but you lost me with the bit about garbage collection. For a beginner, heap allocation should never come up in the first place. If it does, I'd far rather it be as explicit as possible, so they start out having to think about it when they do it.
ted, I think we're on the same page. You shouldn't have to think about it at first.
Well, what I'm getting at is that C++'s problem is not lack of GC for all its heap allocations, it's that you have to make so damn many of them in the first place. For instance, why can't I size an array I'm declaring with a the results of a function call? Why is passing around pointers so common?
@ted. right, which was sort of my point about GC not being the stumbling block, just one of many issues. Perhaps I misread you and you're really saying you don't like GC for newbies, but also don't like hand cranking it. In which case I disagree, but mildly.
I think you're right - it's like getting a kid interested in sport, teach them to love the game first, then work on their technique later..

Go, go, go! Everybody is gonna love you for reiterating their early-on efforts and see themselves in you etc. All the sentimentals aside, yes personally i think you should. You will have much better credibility and hence self-esteem.

+7  A: 

C++ will be (much?) more approachable if you learn "modern C++" rather than "C plus some new stuff". For example, use std::wstring and std::vector<> instead C-style strings and arrays.

The already mentioned Accelerated C++ by Koenig and Moo is one book that does exactly this.


C++ is probably not the best language to start with, and there are much worse choices.

As other have already said, the trick is to learn it correctly, I mean the modern C++ where you'd be able to concentrate (/focus?) on algorithms and the problems to solve, not the C with classes where you'd have to understand memory management while in the early chapters.

AC++ is indeed a very good book to learn modern C++. However without any experience in programming, Francis Glassborrow's You can do it may be a better choice to start with.

Luc Hermitte
+1  A: 

There are two types of languages. The 'kitchen sink' and the 'minimalist'. The kitchen sink language gives you everything under the sun they can think of that might be useful. The minimalist gives you only what you need to develop anything you might ever conceive of. C++ is minimalist. You can certainly write things and share them with others but by default it comes with nothing.

C++ is also (one of) the hardest language for programmers. Managed/interpreted languages do a lot of things for the programmer. C++ does nothing but it also doesn't get in your way or make you pay the overhead of management.

Are you aiming to be an expert with MAD SKILLZ or just playing around?

+1  A: 

Is C++ a good first language?

It's certainly usable as one, as you've found out. I wouldn't specifically recommend it for an introduction to programming in general (I'd prefer Python or Scheme), but it depends on your goals and learning style. I've taught programming in C successfully, and when approached properly C++ is no more difficult.

If your goal is simply to learn C++ for some particular purpose, I really don't know a better method than going ahead and learning C++.

If you like challenges, you might want to jump into C++. The learning curve is fairly nasty, but once through it you'll know a lot of stuff. (People still do learn how to use the vi editor, after all.)

I would recommend learning the higher-level stuff first. Learn vectors rather than arrays, use smart rather than ordinary pointers, that sort of thing. Partly because you should wind up programming like that (for most purposes), and partly because there's less stuff to remember at first. You will need to learn the lower-level stuff eventually, just like you'll need to learn the bit-twiddling stuff eventually.

David Thornley
+1  A: 

While I'm sure C++ is a great tool to have inside one's box, i would carefully advise against learning it as a first language.

C++ is a powerful tool for professionals. You can do horrible things with it ( Sometimes you will have a very hard time trying to understand the errormessages. It has features like manual memory management and pointer arithmetic which clearly have they're place in systems programming and software with very high performance requirements (games...) needs them, but they are are hard to get inside ones head and are not very useful outside those niches. When I switched from c++ to java I really learned a lot faster, but that may be just a personal thing.

I actually don't agree with hiding heap allocations from beginners, but this was well argued, and clearly comes from personal experience. +1
+2  A: 

Ignore the haters. C++ can be a first language. My first language was assembler on the TRS-80 Model 1.

John Dibling
Upvoted for also having written assembler on the old TRS-80. I was pretty good at it also, once.
David Thornley

C++ was the first language I ever did much with. I played with BASIC a bit in middle school, but never really did anything more substantial than a "I'm thinking of a number between 1 and 100" game. I didn't have a whole lot of trouble with C++, but I wasn't self-teaching. In High School, an AP Computer Science class was offered, and we used C++ at the time (College Board was doing the exam in C++; they have since switched to Java, I think). I think it's fine as a first language (or nearly first, in my case), as long as you have a good teacher.

If you're self-teaching, I think you would get more out of Python. You can play with stuff right in a REPL, so there is a lot more instant gratification. The language itself is also a lot more strict in its enforcement of language idioms, which will help you learn the "right" way to do things. C++ won't get in your way if you try to do something the wrong way, and, especially if you don't have a teacher to tell you what you're doing wrong and how to fix it, you will tend to develop some bad habits.

Adam Jaskiewicz
+1  A: 

C++ is a very useful tool and I do often consider mastery of C++ a mark of distinction just because it is such a crazy language.

My advice is learn another language too like python or scheme at the same time. I programmed C++ for quite a long time but when I started learning scheme python and subsequently haskell a whole new world of thinking opened up to me. It is easy to get into the mind set that C++ can do everything and do it faster so therefore there is no point in learning another language.

Basically the faster you can load the more concepts and methods of programming into your head the more awesome you will be at raw problem solving.

One of the funnest quarters I had in college was a class that studied discrete math and functional programming with scheme which was immediately followed by a class that studied computer hardware architecture and used assembly.

I'd go so far as to suggest learning python first (for a short while) and then start trying to pick up C++, but this is sound advice.
+2  A: 

I think if you are sharp and are having a good time with it, then C++ is an OK beginner language for you.

If you asked me the same question without having actually picked one to try yet, I'd suggest starting with Ada instead. It is just as powerful as C++, but far less cryptic.

Also its syntax was designed to be less error-prone, and it does far more compile-time and runtime checking, so you'll spend much less frustrating time debugging your programs. What really turns off a lot of a lot of would-be programmers is when they get nasty bugs they just can't find.

The main thing now that you are using C++ is that, once you get comfortable with it, you go out and try another language. Too many people get so used to one native lanugage that they can't see outside its borders. I can't count the number of people I've seen who hate all languages but their first, simply because they do things differently. But even if you were to stick with C++ as your main language for life, I guarantee you that learning Lisp will make you a better C++ programmer.

Uggg Ada is not a fun language by any means. They used at our university and most people really disliked it. That said I kind of liked some of the stuff in it, just a little to strict for my tastes. I will use bit ops on my integers Ada!!
I've found that folks who seriously dislike Ada tend to have experience in another language (generally C), and want to write their Ada code the way they would write the same thing in C. Ada just will not let you do that without a ton of very frustrating work.

You have a lot of good answers here, but I would add:

Never give up on anything! If you don't have time or something doesn't interest you then you should QUIT, but never GIVE UP!

I don't care how hard it is, carry on. Carry on slowly if you must.

John Gietzen

Where I went to school they taught most classes in C++ (actually it was more of a hybrid C/C++: think C++ but using only C-style strings and no stl), and I think it makes a great first language. It's just the right mix of close-to-the-hardware low-level grunt work to help you learn what's really going on with memory, pointers, and streams on one end combined with object design using high-level constructs like stl collections and garbage collection (boost shared pointers, etc) on the other.

That said, I've moved on to VB.Net and C# now. I still really appreciate my C++ background, and I think it's made me a better programmer having used it first. But I wouldn't want to go back.

Joel Coehoorn
+1  A: 

I think C++ is a good overall first language to learn because it has a little bit of everything. It's not like high level scripting languages where you never really have to deal with types, memory, or pointers and it's not direct-hardware access like assembly. It's somewhere in the middle. If you learn C++ you'll basically have a skill set that will translate easily to other languages.


If you're four months in and doing fine, stay the course. However, I wouldn't recommend C++ as a first language in general.

In grad school, I was a teaching assistant for a first year computer course that all engineering students had to take. The course used C++ as the teaching language and I think now that this was a very poor choice. About 10-20% of the students 'got it' right away and breezed through the course (as a SO user, you're probably in this catagory), the middle 70-90% worked hard and did OK, and the bottom 10-20% were still having trouble telling the difference between a variable declaration and a function declaration half way through the course.

Too many students were bogged down in the syntax of C++ as opposed to using computers to solve problems, which is what a general first-year computer course should have really been about.

Peter Tate

C++ was the first "real" language I started on. Yeah, it was a tough learning curve at times, but the best part there was that since I didn't know any better - I didn't know any better. That is, having not been introduced to anything easier, C++ was the easiest language I had ever used.

Personally, I think the benefits have been enormous. As with others, I managed to become professionally competent in Java in under a week. I was up to speed in Embedded C in a few days. Delphi, VB.Net, C# - all were easy transitions, and I attribute that to having C++ as the baseline.

If you made it past the first few days, you're good to go. By all means, stick with it.