tags:

views:

916

answers:

17

C++ is one of the most used programming language in the world since like 25+ years.

My first job as programmer was in C++ and I coded in C++ everyday for nearly 4 years. Now I do mostly PHP, but I will forever cherish this C++ background.

C++ has helped me understand many "under the hood" features/behaviors/restrictions of many other (and different) programming languages like PHP and Delphi.

I'm a full time programmer for 6+ years now and since I have a quite varied programming background I often get questions by "newbies" as where to start to become a "good" programmer.

I think C++ is one of the best language to start with because it gives you a real usefull experience that will last and will teach you how things work under the hood. It's not the easier one to learn for a newbie, but in my opinion it's one that will reward in the long term. I would like to know your opinion on this matter to add to my arguments when I guide "newbies".

After this introduction, here's my question :

Is C++ (one of) the best language to learn at first for you.

Since it's subjective, I've marked this question as community wiki.

EDIT: This question is not about why Java (or C# or any other language) is better than C++ to start with, it's about what's make C++ a good choice or not a good choice to learn as one of your firsts languages. For example, for me C++ made me understand how the memory works. Now today in many languages everything is managed by the garbadge collector and some people don't even know that. I'm glad I know how it works underneath and I think it can help you to write better code.

+26  A: 

I like C++ but I'd never recomend it as a first language.

As others have suggested C++'s complexity makes it unsuitable for a first language, beginners don't need to worry about backward compatability.

Once you have some programming experience under your belt then there are things C++ can teach you.

  • low level stuff - memory and pointers and RAII oh my!
  • highlevel stuff - templates, generic programming and meta-programming

and looking to the future the good stuff seems to keep comming (c++0x rvalue refs, variadic templates, user defined literals). for a language of its age it is pretty progressive in looking at new concepts, in comparison some much newer languages have virtually no core language change.

jk
+1 seeing the heaps of newbie C++ questions on SO, I have to agree.
Péter Török
Maybe not the first but surely one of the firsts. Maybe I badly worded my question...
AlexV
I agree - I have been writing C++ for 10 years and I still ask [newbie questions](http://stackoverflow.com/questions/2831438/using-mem-fun-ref-with-boostshared-ptr) on SO. New programmers don't need to be discouraged like that...
BlueRaja - Danny Pflughoeft
I disagree. My first programming language was C++, and thanks for that prof. because he chose it over python years ago. It is just not C++ that is impossible to learn, it is how you teach it.
AraK
@BlueRaja: New programmers don't need to know `std::mem_fun_ref`. Yours is definitely not a newbie question.
KennyTM
The point of the question is *why*, not *whether*. If this is what you think, give some reasons why!
Jefromi
I agree, it's a wild beast. It can eat you at any time :)
Iulian Şerbănoiu
-1 - *why* wouldn't you recommend it as a first language? Don't see why this is being upvoted with no rationale.
AshleysBrain
+1 Starting with C BEFORE learning C++ made learning C++ a lot easier (apart from some things which worked differently in C++).
Helper Method
"templates, generic programming and meta-programming" — aren't they all the same set of things in C++? :p
KennyTM
meta-programming can include macros as well, but yes ideally it would all be template based
jk
@AraK sure if you learned C++ first and stuck with programming it won't do you any harm, the problem as I see it is it is more likely to put you off programming altogether than another langugae taught at the same level
jk
C++ was not my first language, however it made other languages I knew then look like children's toys.
Secko
+8  A: 

Well, it's not for me. By far the best language I've ever taught is Python. C is of course the best I've ever learnt but I come from a time when dinosaurs roamed the earth :-).

The learning curve there for students to get a program running and understood is far less than with any other language I've tried (including C++).

paxdiablo
You can learn all you need to about Object Oriented Design with Python, then if you really want to, get into C++ and learn memory micromanagement.
Mike DeSimone
Hurray for C! Have an upvote.
samoz
A: 

As jk has pointed out I also wouldn't recommend c++ as a first language, but for sure I would recommend it at some point in order to familiarize with HW architecture.

Using c++ helps to understand how program is executed and thus write more CPU/memory friendly SW or understand why some things happen.

XAder
If you want to understand HW, learn C or even assembly. C++ will just distract you with templates and inheritance and all of the other OOP concepts, which you would understand better by learning C# or Java.
JSBangs
nopers, you can't learn templates better via c# or java, generics aren't the same
jk
+2  A: 

I attended two colleges in the course of getting my degree. One utilized Java and the other C++. While I'm not extremely fond of either language, Java was much easier to pick up than C++. The school that taught with C++ also introduced Perl to me, which was my favorite of the three.

Ryan
I had the opposite experience. My first college taught C++ and I learned a lot in two classes (because they dove right in and didn't hold back to make it "easy"). The second one is so far using Java and they've tried so hard to make it easy to learn that they don't actually teach anything. Hiding things like pointers from students isn't helping them any (although the gc is useful).
Brendan Long
@Brendan: your name seems familiar - where was your first college?
Paul Nathan
It was just a community college in Colorado (Front Range Community College). I think it might be a community college vs normal college thing (since the community college only has 2 semesters to teach you everything, so they can't spend a couple years pretending pointers don't exist).
Brendan Long
+6  A: 

In my opinion, C++ is NOT a good first language.

You are exposed to way too much at first. Pointers? Memory Management? Templates? Classes? Compiler errors (as opposed to scripting)? AAAAGGGGHHHHH! Way too much to confuse and discourage beginners.

I'd much recommend another language without all this stuff going on.

  • C might work, you still learn the low level pointer and memory stuff, but you get to skip OOP, templates, etc. I'd stil have a hard time recommending C though (it was my 2nd language in college courses, about 5th overall)
  • Java gives you OOP, but saves you from the black hole that is memory management. Lot's of prebuilt classes and libraries so you don't reinvent the wheel too.
  • Python gives you quick feedback since it's interpreted. A lot less complicated stuff going on at first too (but it's there later when you get better)

It's not that C++ is a bad language, the learning curve is just too steep for a first language.

samoz
But if you don't start with C++, you get people who don't even understand how pointers work (and take forever to figure it out). If you start with C++, pointers are just a fact of life that you take for granted. And I completely disagree about starting with C, it's more clunky than C++ (char* anyone?), with no advantage (you could write your C++ code the same way as your C code, but still have the advantage of templates and classes if you want them).
Brendan Long
So what if you don't understand pointers at first? I started with Java and QBasic and didn't touch pointers till college. They really aren't that hard to pick up. Besides, with some of the languages now and what people are developing, many people don't even need to know memory management since those languages manage it. And what's wrong with char*? I <3 char*. I'd much rather deal with a flat block of memory than some ugly object.
samoz
@Brendan If you start with assembly language, pointers become second nature. Does that mean beginners should start with assembler?
FredOverflow
The problem with char* is that you have to deal with all of C's ugly memory management. All that work to save 1 `size_t` worth of memory? People think C++ is hard because of libraries and examples where people still don't just use strings.
Brendan Long
Brendan your argument is confusing. You say C++ is good because you have to deal with pointers and memory management, but then you say that C is bad because you have to use char* and memory management... You can't have it both ways ;)
samoz
No C++ is good because you **can** deal with pointers and memory management. C is bad because you **have to**.
Brendan Long
? If you're talking about new/delete in C++, thats basically the same as malloc/free anyways. In C if you don't want to do memory management, just don't use malloc/free and declare all your variables directly. I really don't see what you mean between a difference in C and C++ with regards to memory management.
samoz
No I mean in C++ you don't have to use new/delete or deal with pointers (at least when you're doing trivial things like you're likely to do in a beginning class). Not to mention that it's much easier once you start if you use classes (if you have `new` in your constructor, use `delete` in the destructor and you won't have any problems). And @samoz: I don't like starting with Java because of all the hand-waving about what everything is. Like how there's value types, and then objects, which are kind of like pointers, but not really ("but pointers are hard so don't think about it").
Brendan Long
I personally have found new/delete to be worse than malloc/free. And what type of beginning things are you talking about that would require memory management in C that you wouldn't need in C++? I'll agree with the Java part. I'm currently discussing in another thread with a guy who insists that Java is the next systems-level language and that it should be used instead of assembler.
samoz
+3  A: 

My first programming language was Pascal. It was the first programming course taught at the school I was attending, and their second course introduced more advanced programming, in C++. In that first course (Turbo Pascal back then, as Windows 95 had only just been released), we were taught the bare basics: variables, functions (and procedures, as Pascal makes the distinction far more verbosely), etc. I have since thought Pascal to be a very suitable language to learn these basics, due to it's fairly verbose syntax. It has its quirks and imperfections, but in the end I am glad they taught us this way. Nowadays I guess Object Pascal might be a worthy successor.

Other than that, I personally wouldn't keep C or C++ too far away from students. I really liked starting off with Pascal and moving on to C++.

Rob
Actually I started with Delphi 3 and then C/C++. I still think that today Delphi is the best very first language to start with. But C/C++ helped me much more than Delphi to learn "low level" stuff (like memory management, pointers, etc.).
AlexV
+9  A: 

Your "question" (which doesn't contain a single question mark!) is full of non sequiturs.

C++ is one of the most used programming language in the world since like 25+ years.

I'm not sure what relevance popularity has. McDonald's is one of the most popular restaurants, but I'd never recommend it to someone looking to eat out for the first time. I wouldn't recommend "pop" music to anyone wanting to learn about music.

I think C++ is one of the best language to start with because it gives you a real usefull (sic) experience that will last

I can't tell what this means. Are other languages not "real"? not "useful"? not "experiences"? don't "last"?

and will teach you how things work under the hood.

Kind of. It will teach you how things work at the level of C++. Whether that's useful really depends on whether you're a C++ programmer. How many C++ programmers do you know who can describe the implementation of new/delete?

If you really want to learn how things work, I don't see how you can avoid going down to at least the level of assembly language and syscalls.

C++ has helped me understand many "under the hood" features/behaviors/restrictions of many other (and different) programming languages like PHP and Delphi.

Ignoring the issue that these languages aren't all that different, you've offered nothing to suggest that C++ is in any way unique here. Couldn't C have offered the same benefit? Or Fortran? Or Algol? To claim that C++ is the "best" is to claim that others are worse, and you've not addressed any other language, nor any unique feature of C++.

For example, for me C++ made me understand how the memory works. Now today in many languages everything is managed by the garbadge collector and some people don't even know that. I'm glad I know how it works underneath and I think it can help you to write better code.

If you understand the design and implementation of new/delete/malloc/free, you're probably a 99th percentile C++ programmer. Almost all of the ones I've met (or interviewed) assume that new is an atomic O(1) operation. Or that new/delete (and malloc/free) are the only way to allocate memory, and don't know about obstacks, or various GC strategies, or how threading and memory allocation interact. But by the time you learn "how the memory works", you've had to go way past C++. No one language can teach you everything you need to know about any one subject, and I still see no evidence that any one is better to learn first.

Ken
I know every programming language have it's legetimity and that no programming language is the best (or maybe even better) compared to each other. ANY experience with ANY programming language is worth something. But since C and C++ are "old" and well established I can fairly think that I can have more job opportunities with them than with let's say COBOL... Anyway this "question" was not intended to prove the C++ supremacy (it's not even my favorite language) nor to start a flame wars. I just wanted to know the positive (and why not the negatives) of learning C++ as one of your first language.
AlexV
Assembly is still too high-level. There is no such thing as `add eax, [ebx]` -- you must learn about micro-operations to really understand what's going on ;)
FredOverflow
"I can have more job opportunities" is like "one of the most used programming languages", in that it's completely different from "best language to learn at first". In the food business, being a McDonald's burger-flipper would give you the most job opportunities, but that doesn't mean it's the best thing to learn -- first, or at all.
Ken
+1  A: 

I don't really think there's so much an issue with the concepts that C++ exposes you to. These are all important concepts; they have to be learned, and in my opinion it's best not to go along sugar-coating them for too long.

About thirteen years ago, I tried to learn C++ as a second language (after QBASIC). I failed, miserably, but the primary reason for my failure was not the concepts involved in C++, but the unfriendliness of the environment. In order to see your C++ program run at all, it has to be completely syntactically correct to even compile, and it has to avoid segfaulting right off the bat due to some silly oversight. And when you are unable to satisfy these requirements, the diagnostics provided are monumentally unhelpful for a novice trying to learn a programming language on their own.

The most important part of the learning process when you are self-teaching is trial and error. In C++ (and C, and largely Java too) if you make an error, you can't even get to the trial part. I remember many times having a small C++ program that worked, and trying to make some tiny change, addition, or improvement to it, only to wind up with a handful of syntax mistakes that caused the compiler to barf out a cascade of a dozen errors and perhaps a hundred warnings. Being a complete novice, of course, I had no way to distinguish which of these pointed to the real problem to give me even the most vague indication of what I did wrong. Normally, at that point, I just had to start over (since of course I knew nothing of version control either!).

Eventually, I abandoned C++ for a year or so and programmed in Visual Basic instead. While I would never recommend VB to a new programmer these days, its advantages for me were that it was very forgiving and allowed me to try things out and see what I did wrong without having my program be an all-or-nothing affair. Later, when I came back to C++ with some additional knowledge of how to interpret errors, and of programming in general, it was much more accessible.

So in short, I'd recommend starting with a language that allows a rapid trial-and-error cycle, has a somewhat forgiving syntax, and provides relatively friendly diagnostics. These days, I think the best candidate for that is Python. It's certainly not C, C++, or Java, although these are all languages that are worthwhile to learn eventually.

On the other hand, it's not unreasonable for C++ to be a first language if it is taught as part of a course where the student has access to a instructor or TA to help them understand what the compiler is trying to tell them.

Tyler McHenry
I taught myself C++ after learning QBASIC. It wasn't 'easy', but I learned how to program in a detailed fashion.
Paul Nathan
+2  A: 

I think the best programming language to begin learning must be general and very high level. This way it can be better learnt the essence of programming. Maybe Python is one of the best, I think.

A: 

In my view starting with a high level scripting language is the best approach. When starting with lower level languages there is a tendancy to spend too much time dotting i's and crossing t's rather than a singular focus on application design. If you end up writing lousy code that can be fixed incrementally. If you end up with a lousy design its a much more difficult problem to address.

In my view problem solving and domain knowledge are the only skills that matter. Languages and their assorted decorations and features are a commodity and should be treated as such.

Einstein
+1  A: 

C++ is a complex language, and as such you have to start with some subset of the functionality. The common case is starting with the C subset of the language (which is not really C, but there are very few differences). Now, some authors as Koening in Accelerated C++, consider that some of the features in the C subset are not necessarily a good start point.

In that particular book, there is not even a mention to pointers in more than half of the book. It starts with the STL, operations on strings, vectors, ... first with plain functions, then it adds classes and builds on concepts that are harder to grasp.

I don't think that approach to be any more complex than the way I learned Pascal, or how Java is presented in my University to students nowadays. Then again, I have read that book after already knowing how to program, so I might be biased and maybe it is harder than I think...

David Rodríguez - dribeas
+3  A: 

I believe C++ is a fine first language.

It has concepts of:

  • memory
  • typing
  • objects
  • inheritance
  • functions
  • iterators
  • strings
  • compilation
  • arrays
  • containers
  • bit-operations

It has libraries for DB access and threading.

It is not easy, but it gets the needed information(both high-level and low-level) into you. It is imperative that a competent programmer know everything from malloc to database access. It presents most concepts in first principle forms, instead of papering over the leaky abstractions. C++ has volumes of information written about it; some of it is even good information. :-)

Its primary power downfall is a lack of closures and first-order functions. Everything else, it has.

C++ has a simple enough start point that complexity can be managed and ramped up from the teacher's standpoint.

Forcing yourself to understand - really understand memory - is required to program at the maximum level of skill. Why defer that?

Yes, C++ is hard. But - programming a real computer is hard. The typical C++ complaints simply expose the essential difficulties of programming a real computer(memory, resources).

There are other good first languages, but I consider C++ to be one of the best due to its depth of expression, combined with its nearness to the 'metal'.

Paul Nathan
C++0x introduces anonymous functions and closures. And C++ always had first-order functions from the beginning, I assume you mean higher-order functions? ;) That also comes in C++0x in the form of functions that take `std::function<bool(int, int)>` or something like that.
FredOverflow
@Fred - yeah. I know the Next C++ Standard will add more power. It's just not here yet. :)
Paul Nathan
Vorfreude ist die schönste Freude. Maybe someone can translate that :)
FredOverflow
@Fred: yes, dealing with the C++1x in practicality won't be as fun as thinking about the permitted awesomeness. :P
Paul Nathan
So... the chase is better than the catch? :)
FredOverflow
Yeah, when you catch something, it's a lot of work. :)
Paul Nathan
+4  A: 

I think that C++ makes a wonderful first programming language. An instructor doesn't have to introduce classes until he's ready. He also doesn't have to introduce the whole idea of references (as implemented in most OO languages) until he's ready, and when you do implement those, it's very explicit when you're using them and how they work. You want arrays? Introduce a bounds-checked vector class.

Ken Bloom
Agreed. C++ is great because you don't have to know any of the hard things, but once you're ready, it's all there.
Brendan Long
Well said. A lot of the comments on this question assumes the student needs to swallow all that C++ has to offer.
Rev316
+1  A: 

As recommended in this article by Peter Norvig which was voted as the best programming article in this thread:

Given these criteria, my recommendations for a first programming language would be Python or Scheme. But your circumstances may vary, and there are other good choices. If your age is a single-digit, you might prefer Alice or Squeak (older learners might also enjoy these). The important thing is that you choose and get started.

mVChr
A: 

I also would not recommend C++.

I think Java is easy to study, rather than C++.

Meteor
A: 

Just found an article that represent what I'm thinking...

I am actually physically disgusted that so many computer science programs think that Java is a good introductory language, because it's "easy" and you don't get confused with all that boring string/malloc stuff but you can learn cool OOP stuff which will make your big programs ever so modular. This is a pedagogical disaster waiting to happen. Generations of graduates are descending on us and creating Shlemiel The Painter algorithms right and left and they don't even realize it, since they fundamentally have no idea that strings are, at a very deep level, difficult, even if you can't quite see that in your perl script. If you want to teach somebody something well, you have to start at the very lowest level. It's like Karate Kid. Wax On, Wax Off. Wax On, Wax Off. Do that for three weeks. Then Knocking The Other Kid's Head off is easy.

From Joel on Software Back to Basics.

AlexV
A: 

My assertion is that writing good code comes from good design. You can learn strong OO analysis and design principles in a language agnostic environment. If you are using Java, C++, or anything else to learn object-oriented principles, you are making a mistake. If you are using Java and C++ to apply said principles, you are well on your way.

With that being said, I recommend C to everybody that asks me. You will learn about lower level things like memory management and how/why to write efficient code, why strings are hard (since you'll be using char[] arrays) and how to write functional code while having the world of OO hidden from you. For me, C is still my base language... I think in C.

Object oriented analysis and design is largely language agnostic. You're almost better off learning about OO separately from any specific language. When you understand the concepts,the principles, and the purpose, you can then learn how to apply them in different languages, as syntax and implementation across different languages may vary. Your time with C will give you an appreciation and an understanding for what is happening under the hood.

baultista