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?
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 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.
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.
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.
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.
</rant>
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.
Many years later, I felt like I should amend this answer. Since my kids asked me to teach them programming, I started to do so. I found myself actually not starting with C++... because I showed them BF first. In absolutely no time at all, they understood about memory and pointers. Then I went on with C++, and we're enjoying ourselves immensely so far.
Yet some more years later, and I felt I really should add this excellent lecture by Kate Gregory from CppCon 2015 to this answer:
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.”
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 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.
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
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.
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.
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.
</rant>
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.
Many years later, I felt like I should amend this answer. Since my kids asked me to teach them programming, I started to do so. I found myself actually not starting with C++... because I showed them BF first. In absolutely no time at all, they understood about memory and pointers. Then I went on with C++, and we're enjoying ourselves immensely so far.
Yet some more years later, and I felt I really should add this excellent lecture by Kate Gregory from CppCon 2015 to this answer:
Stop Teaching C.
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.”