26

A local college is teaching C++ to first year college students (16 years old) with no prior programming experience.

As first programming language, is C++ suitable?

Ed James
  • 1,351
  • 1
  • 10
  • 14
  • 56
    Any language can be a first language. It doesn't really matter. – Adam Lear Feb 07 '11 at 14:48
  • 8
    This might interest you - http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html – Craige Feb 07 '11 at 14:48
  • 2
    C++ (taught C-style) was my first language at 14. I wouldn't recommend teaching the intricacies of templates to college students, but certainly it's do-able. – justkt Feb 07 '11 at 14:52
  • 2
    Why not learn a language that has future career oppurtunities? C# on windows, Java on linux? Those are just two examples. – MVCylon Feb 07 '11 at 15:22
  • 1
    Like justkt, I was taught "procedural C++" as my first language, and other than fostering some biases that linger to this day, it didn't hurt me. – Harper Shelby Feb 07 '11 at 16:09
  • 19
    @Anna Lear: Of course, any language can be a first language, but that doesn't qualify C++ as a good first language. If your answer was an actual Answer, I'd down vote it as unhelpful. – Ed James Feb 07 '11 at 16:11
  • 6
    @Doug: I'm programming C++ for a living... what's your point ? – Matthieu M. Feb 07 '11 at 19:50
  • 2
    With a years worth of teaching you can get a broad foundation in any language (even C++). As long as the teacher knows C++ well then I see no problems in teaching it as a first language and they may even benefit from the exposure it gives to the fundamentals that so many Java and C# programmers seem to be missing. – Martin York Feb 07 '11 at 19:51
  • 4
    @Doug: Thats very short sighted. C++ is here to stay there is too much investment into the language for industry to abandon it any time soon. I see C# going first (though that is unlikely with MS behind it) as it is practically tied to a single platform (even taking mono into consideration). Java will hold on like C++ there is significant investment in its usage. – Martin York Feb 07 '11 at 19:54
  • 1
    @Ed James: on the other hand... why focus on a single language ? I was taught programming from CS theory and by exposure to multiple languages (C, C++, Java, Ada). The principles are always the same, and the syntax peculiarities don't stop you much, especially if there is an assistant handy. I would certainly recommend a helpful compiler though (CLang ?) – Matthieu M. Feb 07 '11 at 19:58
  • My point was more to the fact that OP is 16yrs old. I doubt there are a lot of entry level positions open for C++, even less in 3 to 4 years when OP would be entering the workforce. Sure a lot of people make great money writing C++,COBOL,FORTRAN etc... But I imagine they have been doing it for years. As long as the language is turing complete. Go for it. My point was about future career oppurtunities. – MVCylon Feb 07 '11 at 20:01
  • 3
    @Doug - Wrong. There are junior opening positions for C and C++, even today (if you have the education). Banking one's education only on languages with the greatest numbers of positions typically end up with lowest common denominator skills, limiting themselves to opportunities that - though numerous - are low-paying one-way streets. If he wants to do application level programming, he should focus on what's needed on his senior year (when things are current and hot). A good CS education includes system AND app level programming. One should know more than dynamic web pages. – luis.espinal Feb 07 '11 at 20:45
  • 9
    @Dough - 70% of computing projects today involve writing software for embedded systems and micro devices. Guess what languages are used for those projects? Guess who is best equipped for entry level positions? Certainly not Java or .NET one-trick ponies. Sounds harsh, but schools have done a great disservice to an entire generation of CS graduates by training them only for 30% of the programming job market. We have an overabundance of programmers for the app sector (30%) and we have a shortage in systems sector (70%). Those numbers ain't going nowhere. Future career opportunities? Yeah, right. – luis.espinal Feb 07 '11 at 20:49
  • It was just my opinion. I've learned Basic, cobol, java, vb6, vb.net, c#, C, and my first intro to programming class had us write our own language. That's how you learn a language. – MVCylon Feb 07 '11 at 20:53
  • My final thought. We do not need 10,000 developers trying to write the next sort algorithm. – MVCylon Feb 07 '11 at 20:57
  • Yes, everyone, please stick to Python, .NET, and Java. The supply-demand curve will definitely favor me. :-) – Paul Nathan Feb 07 '11 at 22:39
  • 4
    @Doug - I know it's your opinion, and I respect that. But opinions aren't fact (.ie. some have the opinion that evolution is a lie). Your previous statements (your opinion) regarding future career opportunities is not supported by industrial statistics. You had a particular experience on how to learn a language. Great, how does that relate to future career opportunities? Also, your comment regarding the next sort algorithm makes no sense. You don't learn algorithms so that you implement them over and over, but to understand how to intelligently do performance analysis (a part of one's job). – luis.espinal Feb 08 '11 at 00:13
  • 2
    Funny. We just started programming on school today. My class (including me myself) consists of only 16 years olds. Unfortunately the teacher wants us to learn StructoGraaf (an idiot program where the 'programming' is simply designing a PSD) (even worse is that it's Windows-only while I don't have Windows at home!!). I simply ignore the teacher and I've already installed Clang and Emacs. :) –  Feb 08 '11 at 23:28
  • @AnnaLear: indeed any language can be first but it DOES matter, and can matter a lot. – Balog Pal Jul 01 '13 at 23:39

25 Answers25

60

Emphatically No.

For any goal you have in mind for students, another language or sequence of languages would be faster and better. Examples.

"Students need to understand low-level concepts."

"Low-level" coding does not consist of getting objects from new, feeding them back to delete, and occasionally having a pointer pointing somewhere it shouldn't. Functions, classes, and templates are not low-level. RAII, 12 ways to use const, std::ostream::operator<<, protected and new are not low-level concepts. Those things have low-level implications and you're skipping those for months or until a future class and teaching mountains of C++ semantics instead.

I suggest assembler with a good environment and teaching material like MIPS or MMIX. If you're in a hurry, teach C with detours to at least look at the assembler output. This will give you all the low-level understanding C++ does, and then some, faster.

"Students need to understand object-orientation."

The object-orientation built into C++ is way overcomplicated for teaching OO concepts, or almost any other high-level concept. See The C++ FAQ for a nice, long list of potential reasons why. You either have to hit all of that stuff, which will take a very, very long time with new programmers; or else you have to skip lots of it, leaving the new programmers in the dark--effectively, not really knowing C++!

I suggest learning a simpler, high-level language with objects first (Python, Ruby, Squeak, Common Lisp, Racket), if you must teach C++ at all. Beyond that, learn polymorphism as a concept that is separate from OO by visiting a functional language.

"Students need to understand templates and template metaprogramming."

No one really asks this, but I wish they would. C++ has nice templates and STL is cool, but they just shouldn't be a high enough priority to teach C++ first. Teaching the OCaml or Haskell type system and then retrofitting those concepts might be faster anyway.

"Students need to learn problem solving."

Yeah, you get this in any language, and you get more if it in almost any language other than C++ because there's way less baggage. Again, see The C++ FAQ for a list of all the things students will be learning instead of problem-solving skills.

"All of the above, and we need to use only one language." or "Employers want it." or "We need a C-style language." or...

Teach more than one language.

The idea that you save time or energy by teaching or learning just one language is flatly ridiculous. It's based on the idea that learning any given language takes exactly X man months (HINT! HINT!) where X is a single number or one number per language. This is nearly identical to the idea that you can save time and money by skipping all that 'requirements' and 'testing' garbage.

As for multiple syntaxes, you dangerously cripple students if you teach them to expect the C syntax in every language by making them wildly biased against other languages.

Almost any path is faster and better than starting with C++. Learning a simple high-level language and then C++ would be faster. Learning assembler and then C++ would be faster. Anything other than C++ will get students there faster and they will know way more to boot. Just don't teach C++ first.

Jesse Millikan
  • 1,601
  • 15
  • 22
  • 4
    Great answer! Indeed, many C++ features are not at all related to low level programming. – Marco Mustapic Feb 07 '11 at 23:35
  • 7
    +1, excellent answer. It's true that sometimes C++'s whims are mistakenly equated with "low-levelness". You linked to the C++ FAQ, but I would also recommend people take a look at the [C++ FQA](http://yosefk.com/c++fqa/) (or "Frequently Questioned Answers" :P ) – Andres F. Feb 08 '11 at 20:48
  • 2
    Wow. That reminds me of the [Java IAQ](http://norvig.com/java-iaq.html)... – Jesse Millikan Feb 08 '11 at 21:12
  • Completely agree. Even Malbolge would be better than C++ for a beginner. –  Feb 08 '11 at 23:37
  • +1 great answer. I'd only add that if mataprogramming/templates etc. are the objective then it would be far easier to start with a homoiconic language like one of the Lisps (Scheme or Clojure perhaps) – mikera Nov 03 '11 at 10:12
  • 2
    My only reservation - you can teach a lot without getting into the details that are mostly only relevant to people developing libraries. So long as you make it clear that you're only doing basic C++... but then again, what have you taught anyone anyway? –  Nov 03 '11 at 10:38
  • +1 just because it is not possible to +n, for n > 1. – Giorgio Apr 26 '12 at 18:11
54

No, C++ is a difficult language even for experienced C++ developers. Even for the simplest algorithms you have to explain many of the language subtleties. Consider a Hello World example:

#include <iostream>

int main()
{
  std::cout << "Hello World!" << std::endl;
}

What's that #include command? What's std::cout. Why the ::? What is <<? Ohhh, it is an overloaded operator! What's an overloaded operator? Sooo, for ints, it does bit shifting, but for whatever std::cout is, it outputs stuff to the console. Ohhh, std::cout is a stream, and streams have their << and >> operator overloaded.

Let's see the same sample in Python:

print("Hello World!")

That's it, let's go code some algorithms.

James McLeod
  • 7,613
  • 4
  • 21
  • 34
Marco Mustapic
  • 286
  • 1
  • 2
  • 8
  • 15
    Python will be suitable for a seventh grader. A college student can grasp much more. – Gulshan Feb 07 '11 at 15:47
  • 13
    Sure, but we are talking about a first language. C++ is known for being difficult to learn and master, compared to other languages. Why use it to teach programming? A student can learn C++ later, when he knows some programming basics. – Marco Mustapic Feb 07 '11 at 15:56
  • @Gulshan: I'm from UK and these students are mostly 16 years old. How old are seventh graders? – Ed James Feb 07 '11 at 16:03
  • @Ed James about 12. – Gulshan Feb 07 '11 at 16:08
  • 8
    You didn't even mention the argument-dependent lookup of << :) – MetricSystem Feb 07 '11 at 16:23
  • 1
    @Gulshan: a college student can grasp much more, but the question remains, "is C++ _'much more'_ than Python"? It's certainly more _difficult_, but is it more _suitable_ for the kind of problems a college student should be trying to solve? – Andres F. Feb 07 '11 at 17:14
  • 6
    You don't need to know absolutely everything to get started with a language. cout << whatever; "just works", you don't need to go into the nitty-gritty details until you cover operator overloading etc later on. – Colen Feb 07 '11 at 17:36
  • My first C++ program (which was my first programming experience) was simply typing out what was given to me on a sheet of paper. I learned the programming concepts later. It wasn't until working professionally with C++ that I began to understand some of the intricacies, but that didn't matter at the time. My teacher taught around the hardest stuff and we still learned flow control, input-output, the basics of pointers, and recursion. – justkt Feb 07 '11 at 18:45
  • 6
    I'd take Python over C++ any day of the week as an introductory language. – jprete Feb 07 '11 at 18:52
  • 3
    @Colen: You don't need to know everything, until you get a crazy compiler message filled with pages of template error messages (since the standard library is all templates). The complexity of the language ( and the limitations of its parsers ) is reflected in the error messages, which beginners get a LOT of. – MetricSystem Feb 07 '11 at 19:25
  • 5
    I like the "weed out" effect that c++ has. If you have an interest in programming then c++ should be no problem to learn, just study :) – Dalton Conley Feb 07 '11 at 20:32
  • @Dalton - Bingo, the weed out effect is the most important and beneficial thing, for a CS program and for CS students. People don't realize the importance of this (*you either get or you don't, really.*) C++ can be taught with a C approach, or one could simply use C. Either language has been used successfully as an intro language. Hell, people used to learn programming using Assembly and did well, and understood things better. Obviously, something like Python, Basic, Pascal or Ruby could be better as intro languages, but the sooner you get to the metal, the better down the road, educationally. – luis.espinal Feb 07 '11 at 21:08
  • 1
    As someone who has taught a 2nd-level college programming course to high school students in a 2 week span (It was an "interesting" challenge), I can tell you it _can_ be done. A strategy for success can be to focus on certain parts of the language to start. For example, you can teach a programming course using C++ but teaching only C concepts and using almost entirely C syntax. – mummey Feb 07 '11 at 21:16
  • Exactly, you can teach pointers, memory management and low level programming with C. Even in these areas C++ is more complicated, as a first language. – Marco Mustapic Feb 07 '11 at 21:26
  • 5
    @Dalton, why "weed out" people? Programming it's not some kind of boot camp where you have to toughen people up. You may be discouraging people just because of a poor initial language choice. Make it interesting and fun in the beginning, enable the students to get immediate results, and then go deeper and teach them lower level stuff. Or even bad language design decisions like C++ has. – Marco Mustapic Feb 07 '11 at 22:03
  • 1
    @Marco, without the weed out effect people would end up in a class like "Advanced Design Patterns" and not understand any object oriented language. PHP was my first language, and self-taught at that and I can honestly say it was a mistake. It took away realistic views of a real programming language like c++. – Dalton Conley Feb 09 '11 at 20:09
21

It's probably not a good first language: complex syntax, lots of rules, old language, error-prone memory management. Better to teach your students something more OO like Smalltalk, or something nicer to program with like Python, or something functional like Haskell.

They can learn C++ later in life (if they can't help it), after they've learned better languages.

Andres F.
  • 5,119
  • 2
  • 29
  • 41
  • 5
    Haskell as a first language would be an interesting experiment. – Larry Coleman Feb 07 '11 at 15:39
  • @Larry, Cambridge University's CS course teaches SML as the first language. – Peter Taylor Feb 07 '11 at 18:43
  • 1
    Functional programming twists your brain - I know MIT starts out with Scheme pretty early on, but I am glad I wasn't started on functional programming until after two years of a hybrid proceedural/OO-style in school. – justkt Feb 07 '11 at 18:47
  • 11
    @justkt: All languages twist your brain. It's just a matter of how you want it twisted. – David Thornley Feb 07 '11 at 22:27
  • +1, but I wouldn't categorically label languages other than C++ as being necessarily "better." – greyfade Feb 07 '11 at 22:29
  • @Peter: Are they still using it? It was certainly in use back when I was there (and as I transferred in from another course, I had to spend the summer learning SML from a book while on vacation; wonderful pseudo-mathematical fun!) – Donal Fellows Feb 07 '11 at 22:58
  • @Donal, I checked the CL's website before posting that to ensure I wouldn't be shown up as an old codger. You had to ruin it, didn't you? ;) – Peter Taylor Feb 07 '11 at 23:19
  • @justkt - if a language doesn't twist our brains, then either we are super-talented or the language does not have great interesting (positive or negative) features to learn from. Learning functional programming from the start should be no problem with Lisp or JavaScript (which have very simple syntax). But Haskell... hmmmm, not sure. – luis.espinal Feb 08 '11 at 00:19
  • @luis.espinal - maybe it was just me, but C-style C++ at 14 (even with recursion and simple pointer arithmetic and memory management) was nothing on the pain of Lisp at 17. – justkt Feb 08 '11 at 00:21
  • @Peter: I'm just trying to think (well, pretend to myself) that I'm not an old codger… – Donal Fellows Feb 08 '11 at 10:00
18

Short answer: Yes!

I would say that any language is a suitable start but especially C++ (or equivivalent). These days C# and Java are major languages in use and programming with these you quickly learn to lean on the API and IDE's but with C++ you get a chance to learn programming from the ground up, including performance optimization, etc.

It's never a bad idea to learn the basics of programming, looping and sorting before you just blindly rely on a languages built in .Sort();

Mantisen
  • 306
  • 1
  • 6
  • 11
    Looping and sorting, yes. You can do that with any language. But why start working with pointers and weird syntax when you can avoid it? You can learn all those things later, when you have more programming experience. – Marco Mustapic Feb 07 '11 at 16:03
  • 4
    @Marco: Stroustrup's introductory textbook "Programming: Principles and Practice using C++" introduces pointers at about the middle of the book. You can do a lot of stuff in C++ without introducing pointer. – David Thornley Feb 07 '11 at 18:35
  • 4
    “It's never a bad idea to learn the basics … before …” do you have *any* research to back this claim up? I know that many smart people tout it as common knowledge that “bottom up” is the only true way of teaching but this is a **very** controversial point and the only (admittedly very limited) didactic research that I know points to the opposite conclusion. – Konrad Rudolph Feb 07 '11 at 18:42
  • 1
    @David: The problem is, doing "a lot of stuff in C++" without pointers is even worse. Without pointers, all your objects get declared on the stack, which is one of the worst programming ideas EVER. Value types and inheritance/polymorphism just don't mix, and trying to mix them leads to entire categories of errors that don't exist in better-designed languages. – Mason Wheeler Feb 07 '11 at 18:45
  • Pointers were the worst thing for me to understand, coming from QuickBasic - right after getting over the 0-based array/string indexing. And that a string is also an array just flummoxed me to no end. Starting there is GOOD. If you can't grok that, you're going to have trouble with larger concepts. – Chris K Feb 07 '11 at 20:13
  • 9
    Oh god, no! Why burn limited supply of brain cycles on unnecessary idiosyncrasies of C++? Why focus on irrelevant low level stuff, like memory management, when the objective is to learn basic concepts in programming? Why jump into the deep end?! – Maglob Feb 07 '11 at 20:45
  • @Marco - empirical evidence tend to suggest people with talent for programming will get pointers from the start and that people that lack that talent will not properly get pointers no matter when they get introduced. – luis.espinal Feb 08 '11 at 00:16
  • 1
    @Konrad: I wasn't trying to tout "bottom-up" learning as a far superior way of learning. In my own opinion a "bottom-up" approach is not always the best way of learning. However I've never been in a situation where "knowing the basics" have been bad. – Mantisen Feb 08 '11 at 11:41
14

Actually I believe it probably is a good choice as a first language for a very practical reason: After learning C++ any other language you encounter will seem like a breeze to learn.

ennuikiller
  • 1,168
  • 7
  • 8
  • 10
    With all due credit to Dijkstra, it is practically impossible to teach good programming to students that have had a prior exposure to C++; as potential programmers they are mentally mutilated beyond hope of regeneration. ;) – Mason Wheeler Feb 07 '11 at 15:24
  • 3
    They would have to unlearn a lot of bad habits from C++. To use another example, does knowing assembler make you a better Java programmer? I'd say it does NOT. – Andres F. Feb 07 '11 at 15:51
  • 16
    @Andrés F.: Gotta disagree with that. Knowing assembler makes you a better programmer no matter what you're writing in, because then you can understand what's really happening. – Mason Wheeler Feb 07 '11 at 17:23
  • 2
    @Andres: I've seen too many Java/C# programmers coming to other languages and cramming everything into objects... they lack breadth of experience. – Matthieu M. Feb 07 '11 at 19:53
  • @Matthiew M.: I fully agree. But the problem in those cases is that not everything is suitable for OOP. How would learning assembler or C++ help those programmers? C++ is too close to Java/C# and assembler is completely detached from high-level programming. – Andres F. Feb 07 '11 at 20:20
  • 3
    @Andres F. - In my 12 years doing Java, I've encountered my share of Java programmers that truly suck for not having any sort of exposure to matters such as resource allocation, RAII, not knowing how to program gc-friendly applications, etc. Knowing assembly and knowing compiled languages without automatic garbage support and with support for paradigms other than OO (C, C++, Ada, or just about any compiled language on the Algol family) teaches you how to write efficient **and large** systems in Java, C#, Python, you name it. Plus, the object model in C++ is not that similar to Java, at all. – luis.espinal Feb 08 '11 at 03:05
  • @luis.espinal: sorry, but your Java programmers suck if they can't do resource allocation. And sorry again, but experience with Algol-inspired languages is in no way a prerequisite to understanding programming. It's just that that's the way many of us learned (myself included), but it's not the only way nor the best way. – Andres F. Feb 09 '11 at 03:36
  • @Andres F. - *"sorry, but your Java programmers suck if they can't do resource allocation"* - isn't that what I just said? Here, see, that's my line (*"I've encountered my share of Java programmers that truly suck for not having any sort of exposure to matters such as resource allocation"*). You pretty much just repeated what I said. – luis.espinal Feb 09 '11 at 15:29
  • @Andres F. - *"And sorry again, but experience with Algol-inspired languages is in no way a prerequisite to understanding programming."* - No need to be sorry, and besides, that's not what I said. I said that training in a compiled Algol-like language helps with programming. I did not say it was a pre-requisite. Logically, the former does not imply the later (in a very deep *p -> q* kind of way.) – luis.espinal Feb 09 '11 at 15:42
  • @Andres F. - con't - Also, we know that non-Algol languages such as Lisp or Forth are also good for teaching (which is not contradictory with what I said wrt Algol-languages). It just so happens that Algol-languages are more widespread, with learning resources in greater abundance. Thus, one can reason for using Algol-like languages as the first taught language, purely for logistical reasons, independent of the merits of non-Algol ones (and without implying - as you thought I did - that Algol-languages are a must.) **In other words, I don't what message you were trying to convey.** – luis.espinal Feb 09 '11 at 15:53
10

I taught myself C++ when I was 15-16.

It is better to leave the magic to others and to learn the inner workings of things yourself.


Bluntly put, if you can't figure out entry-level C++ syntax and semantics, you're not that good at computers. It's not that hard. There's no good reason to avoid "C with Classes".

If you expect students to start working on template metaprogramming, deducing polymorphic calls, and untangling multiple inheritance hierarchies - that's ridiculous for an entry level class for whatever sort of language you use.

There's a very bad tendency to want to hide the intricacies of programming for students. That does not end up well( c.f. Spolsky's Java Schools essay). Those people end up on the DailyWTF if they do not get their head straight. Abstractions leak, and when (not if) the abstraction leaks, that is worse than having to deal with it. I've worked as a TA for entry level C++ students. Either things have to be hidden all the way, or they have to brought into the light to be examined. Magic is the enemy of the learner.

If I had to recommend a starting language that compiled to machine code, a Pascal variant would probably be the best approach. It has a more regular and structured approach than the C family from what I recall.

Paul Nathan
  • 8,560
  • 1
  • 33
  • 41
  • Did you know how to design programs before you learnt C++? – Ed James Feb 07 '11 at 17:07
  • 1
    @Ed: Not really. I had mastered If and Goto in QBASIC, and that was about it. Pointers, arrays, functions, classes, etc were all in my C++ future. Recursion was incomprehensible as well. – Paul Nathan Feb 07 '11 at 17:15
  • This is the answer I would give as well - I think a lot of people answering here are forgetting the *simple* stuff you can do with "C with Classes" that has nothing to do with any of the hard stuff. It is about as easy to print out the sum of two numbers to the console in C++ as in Java. – justkt Feb 07 '11 at 18:49
  • 5
    Wait, nobody expects someone to work on a project using C++ without first _understanding_ C++! That would indeed lead to code worthy of TheDailyWTF. But contrary to your claim, it's _not_ trivial to learn C++ (and it's not "C with classes", either). C++ has huge, convoluted and sometimes non-sensical syntax and grammar, and an infinity of keywords and rules. It's a _horrible_ language to start with. As a teaching language it's awful because it conditions students into thinking C++'s deficiencies are natural and unavoidable in the programming world. – Andres F. Feb 07 '11 at 19:09
  • 1
    Andr: You are insisting on a false dichotomy: "~C++ or All C++". That's fallacious. – Paul Nathan Feb 07 '11 at 19:13
  • 1
    @Paul: fair enough. But consider this: even the syntax & grammar of a simplified C++ is convoluted because it must support all the features of the full language. So you've already compromised on using an ugly language, even if you teach it in its simpler forms. I'm assuming you are not just coding in C with some syntatic sugar (aka "C with classes"), because in that case you're better served by plain C! – Andres F. Feb 07 '11 at 20:27
  • 2
    @Andr: Not really. C++ offers considerable syntactic simplification over C89. Further, for the entry level purposes, things are very straightforward for all the of the cases I can think of... – Paul Nathan Feb 07 '11 at 20:32
  • The idea is to make people good at computers by teaching them an appropriate language first. Not discovering some kind of "good at computers" gene. – Marco Mustapic Feb 07 '11 at 23:31
  • @Marco: Python, Java, etc, etc, do not teach you sufficiency about the computer. – Paul Nathan Feb 08 '11 at 04:14
  • The issue is about C++ as a first language, not as the only language being taught. As a high school student I learnt Pascal, and not knowing enough about the computer wasn't something preventing me from learning algorims. I just learnt C and C++ later. – Marco Mustapic Feb 08 '11 at 19:19
  • @Marc: Pascal and C share similar characteristics: raw memory access and compilation to machine code. Those characteristics are needed for machine-level operation and open the door to dealing with the physical computer. Pascal, Algol, PL/1, C, C++ and D all have those sorts of capabilities, with varying levels of syntactic and semantic noise. Dealing with the computer is a must. Algorithms, syntax, semantics, and the computer operation go hand in hand with how programming works and each must be brought in such that the learner can form a mental model that helps them learn. – Paul Nathan Feb 08 '11 at 21:14
8

I would say 'no'- I had an eagerness and desire to learn programming, and went right into my intro year at college with C++ right off the bat. Coupled with a teacher who was teaching C++ as if it were another language (concepts that made sense to them, not necessarily concepts of the language or real world application), and projects thrown at us right away every week, I crashed and burned along with half of the class. By the time I could even digest, experiment and apply what I was being taught, I struggled with the project homework which doubled as tests. I would argue that it was more a 200 level course than 100.

I really tried my best. I didn't ask for sympathy, I knew it would be a challenge, but the teacher wouldn't even help me. Just told me to go read the textbook, as I had been doing.

I would argue (and some would disagree) that Ruby or Python is a much better language to break someone into the world of programming. Clean, concise, readable, clearer syntax.

Kevin
  • 298
  • 1
  • 9
  • 8
    Any language is a bad first language if taught badly. – David Thornley Feb 07 '11 at 18:36
  • 3
    @David Thornley: however, even when taught correctly, some languages are a poor choice as first languages. For example, Cobol. – Andres F. Feb 07 '11 at 18:56
  • I do agree, I feel that with a better teacher, one who cared to engage others and not just get through course material at lightning speed, the outcome may have been different. It just rolled too fast for me. – Kevin Feb 07 '11 at 19:00
  • @Andrés F.: I'm not disagreeing with that. However, Kevin's account was about a bad teacher, and a bad teacher can screw up Python or Scheme as a first language (my two nominees for good first language). – David Thornley Feb 07 '11 at 19:06
  • @Andres F: I managed to avoid COBOL for nearly 15 years until I took my latest job. I would like to think that for a certain class of software COBOL is amazingly elegant. – Chris K Feb 07 '11 at 20:17
  • 2
    @Chris: I've programmed in Cobol and I pity you :) – Andres F. Feb 07 '11 at 21:44
  • @Chris: For quite a few years I wanted to think that COBOL was a good language, but I never could convince myself. It was so nice to get a programming job in another language. – David Thornley Feb 07 '11 at 22:28
8

No.

As a teaching language, C++ is only marginally better than C, which is one of the worst teaching languages around. It introduces a lot of complexity up front, some parts of the language are deeply non-intuitive, and most of the time you're learning more about C++ than about programming in general.

That's not to say that C++ (or C) are bad languages, or aren't worth learning; just that there are better teaching languages available, such as Python.

John Bode
  • 10,826
  • 1
  • 31
  • 43
  • 1
    C is a hard language for teaching, but it is certainly among the worst. COBOL and Java take the cake as being among the worst, much worse than C. The good thing about C is that you have to deal with the inner metal up front (without having to delve into assembler). People have successfully being taught with C as its primary language. There are other, more elegant options, of course, like Python or Ruby (or any language that is multi-paradigm and that doesn't needlessly shove OO up front for even the simplest of tasks.) C is not one of the worst teaching choices, not by a long shot. – luis.espinal Feb 09 '11 at 16:00
  • 1
    Marginally better? How do you figure? C++ takes everything that's bad about C and *builds on it*! – Mason Wheeler Apr 05 '12 at 12:41
  • 1
    @MasonWheeler: Mainly because C++ provides an honest-to-God `string` data type that overloads operators like `+`, `=`, and `==` to do things that students more-or-less expect, compared to how string processing needs to be done in C. Hence "marginally". I wouldn't recommend either as a teaching language. – John Bode Apr 05 '12 at 18:12
7

There are two essential types of post-secondary education: the university and the trade school. The difference is in what you want to be prepared to do after graduation. In the automotive field, it's whether you will be a mechanic or a mechanical engineer.

That being said, C++ is a great first language if you want to be an engineer, and a lousy one if you want to be the programming equivalent of a mechanic.

An intro class on C++ is going to spend a lot of time talking about data types, definitions, declarations, pointers, memory allocation, and so forth. These are a great foundation if you intend to spend several semesters building up to being able to do anything useful, but want to know that once you get there you have the foundation to handle any degree of complexity.

On the other hand, if you want to be able to do something useful more quickly, but don't mind if the domain and complexity are limited, then spending all that time on those lower level concepts up front is going to be a waste. There are plenty of programmers who can write a great html form validator, but don't have a clue how to approach designing a device driver.

Karl Bielefeldt
  • 146,727
  • 38
  • 279
  • 479
5

Sure. My first language was C, but that was really just to ease our class into C++. It made Java much easier to handle once I got to University. C++ might have a slightly steeper learning curve, but if it's taught properly it should be fine.

FrustratedWithFormsDesigner
  • 46,105
  • 7
  • 126
  • 176
4

No, C++ is not suitable as a first language. As shown here, many professional programmers share this opinion, but this is also an opinion that professional teachers have.

Here is what a report from the dean of Carnegie Mellon University has to say about using C++ for an introductory course to programming for freshmen:

Standard languages such as C or C++ are not suitable for this course because their complexity and deficiencies impede both informal and mechanized reasoning techniques.

CMU offers two introductory courses, an imperative one and a functional one. SML was chosen for the functional programming. I don't know what was chosen for the imperative course, but the report mentions using a subset of C.

Joh
  • 469
  • 2
  • 10
2

Sure. There are other languages that might be easier for first year students to grasp. However, there are ways that a teacher could slowly introduce concepts in C++.

jzd
  • 4,166
  • 25
  • 28
2

Definitely C++ can be the very first language. But it's about how well it is taught.

Everyone says, the first language should be very easy to grasp. But my point is, most of the people start programming in undergraduate level. So, you can teach something they are capable to grasp. And with C++, you can go from lower level to higher level of programming.

Gulshan
  • 9,402
  • 10
  • 58
  • 89
  • But why not start at a _higher_ level of programming? It's the level at which we solve most problems (except for certain domain specific problems, of course). Then, if they need to get closer to the metal, they can learn C++, assembler, etc. – Andres F. Feb 07 '11 at 18:59
  • I agree, its about how well it is taught! – Gary Willoughby Feb 07 '11 at 19:06
2

No. Absolutely not.

If I had my way, I would disallow it's use in an academic setting almost entirely. Not for reasons that are contrary to those already made, but because too many think C++ (or it variations) is the answer for nearly every problem because you can use it in nearly any situation. It is the screwdriver of programming.

Some people use it to tighten screws, a perfectly reasonable tool for the job. Others use it like a prybar, while often effective, not really ideal because a screwdriver, no matter what your father might tell you, is not a prybar, and may catastrophically fail due to misuse because the composition of the shank isn't intentionally built for the kind of forces a prybar would encounter. Still others might try and use it as a punch or a chisel, and they will almost always encounter problems because the handle of the screwdriver wasn't built for the kind of striking abuse that punch or a chisel is designed to withstand.

In my opinion, the job of a programmer is to generally translate real problems into automation that provides some degree of improved efficiency (decrease committment of resources to a task), velocity (decrease the time to perform a task), predictability (increase the repeatability of a task), or organization (increase the awareness of relationship between tasks).

While it is understandable that everyone who programs should have some common knowledge about low level operations of computers, and specifically device IO and memory allocation, it is definately uncommon to really have to utilize that knowledge to any significant degree, let alone leverage it for the vast majority of tasks. Attempting to do so without understanding the broader context of the problem inserts uncessary risk to an effort.

It is absurd that a first programming language should be C/C++ or close variants, as the class of problems that C and its derivatives solve are certainly not apppropriate for some arbitrarily large percentage of the current and future problems (except where one has to rescue a previously, screwdrivered program), and in fact is more of a miniscule set of coming problems. Most programmers will never come close to developing core OS features or direct device interfaces, despite increasing prevelance of small mobile, interconnected devices. Most will work and live like we did. Fixing and phasing out code that is more than two generations old, implementing on technology that is already showing age, or working in the fringe of technology on the killer(x+1) app.

For a first language, I would look at Lego NXT, a light duty but highly feature rich variant of LabView. While Lego NXT is not used widely in commercial ventures, it will present the fundamental nature of what it is to program in a "sensor rich" way. I might pair it with a somewhat platform neutral scripting language like Javascript or TCL/TK. Both would be relatively low impact in terms of what you have to discover to do very basic but effective tasks, with high return in terms of the feedback loop and flexability to introduce and solve varying degrees of problem complexity. Plus, it provides a good opportunity for students as they advance to explore the potential for exceeding what is provided in the canned environment: a chance to try working in the dark, damp, low-level places of device IO and custom drivers with a small amount of overhead.

After they learn to drive the four cylinder automatic, then step them up into the big v8 manual hotrod, if they are really interested and motivated. If Joel can't find the rock-star programmers under any stone beneath his feet, he just may have to keep looking somewhere else, or rethink why he may need more than a bunch of screwdrivers in his toolbox.

JustinC
  • 3,306
  • 17
  • 20
1

Some of points where beginners easily make mistakes in C++ are:

making assignments where you wanted to test = vs ==

Missing ;

Readability of curly brackets vs. for example pascal begin-end

And then there are all the include files, macros, memorymanagement etc. to confuse.

So I would say C++ is not the best language to start with - however there is no doubt that it can be very usefull when you have learned it.

I would - as others also suggested - use C#, Java or maybe even VB - and a good IDE with syntax highlight, debugger etc. to help make it easier to recover from errors.

1

When I was in college C++ was the foundation language that was taught throughout the first year of college. The theory was that it contained some complex programming concepts, so if you could master it, you could pick up other languages. It served me well as a good foundation.

Having said that, during my senior year, I served on a committee to determine whether or not to switch the core language to Java. After talking to several prominent employers and some alumni of the department, it was determined that a switch to Java was the best interest of the students. The employers we talked to wanted people to have experience in a language they were using in order to hire them. I believe now, 10 years later, they are still using Java as their core language.

On a similar note, we have been looking to hire a couple of recent college graduates with really good C++ skills. We haven't been able to find any.

SchwartzE
  • 281
  • 2
  • 6
1

I would say yes. But any language can really be a first language. I think C++ is good because while it's complex and sometimes difficult, it shows you what you can really do (less limitations). Also, it has some object oriented design that can help you get ready to take on other languages.

C++ was my first language and I'm glad it was. It got me thinking in the OOP mindset early on and I'm thankful for that. But in the end, it really comes down to what you want to do. The language doesn't matter as much because if you can get good with one language, chances are you're not going to have any problems picking up another. What do you want to do? Make games? Program for mobile phones? Each one will have tools and languages better suited for it.

1

C++ is an expert language, not a beginner one... would say C first, not Java or C# or Python... why? because C teaches you to take care about your memory and some tricky concepts such as pointers which are "hidden" by all languages yet being present everywhere. I've seen so many young developers who don't even understand why memory should be released sometimes and believe the garbage collector is not a little dwarf that cleans all coding craps: they instantiate, they instantiate and boom it explodes even if they have XXXXGb RAM... But they don't understand why the garbage collector is not simply magically cleaning everything! And I've seen this kind of developers coding in C++ (and even crazier, in Corba) and it was a slaughter!!!!!!!!!! So I would advice to learn coding in C and then go to Python/Java/C# for the object concepts and all sugar around. Then when you understand all of that, you go to C++ and you feel the power of C++ but you also discover all its dangers and why it shouldn't be used by anyone ;)

mandubian
  • 101
  • 2
1

NO. There is so many stuff that C++ has, that makes difficult for a newbie to understand. Don't get into the "all programming languages are equal" fallacie.

Start with Basic or Pascal, (ignore the "they are deprecated" stuff), and later, with C/C++/Java/C#/Perl. Or if you have a chance, first with Logo & Karel, and then Basic or Pascal.

P.D. Some universities & collegues have a Programming Language usage & comparison class, and it happens that I had teach that class ;-)

umlcat
  • 2,146
  • 11
  • 16
0

If "suitable" stands for "possible", yes. If for "good", definitely no.

It's possible to like, even love C++, but for that you better learn several languages and work some decade with teal-life rotten codebases, get experience on "crafting nontrivial software that works actually" -- then C++ will have charm.

Not at start when you are virgin, fiddle with small, simple (but supposedly interesting and fun) problems.

I'd start with python, followed by SICP (scheme), or something similar. Maybe reversed or interleaved. With those you can just go and deal with the problem. Instead of fighting the system, walking in deep mud and learn all kinds of illogical quirks and their historical reasons.

Later, when you already can program your way out of a paper bag, switch to bare metal: learn ways of assembly and several architectures, plus maybe Knuth's Mix. I don't mean memorizing opcodes or do much real stuff, just to understand memory, registers, the ALU, caches, interrupts, and get on read level.

Then with that foundation you can be exposed to other languages, including C++. Maybe a good idea to add some "history and evolution of languages" in between.

Balog Pal
  • 1,711
  • 9
  • 16
0

You can choose any language to learn the foundations of programming. I learned stuffs in C/C++. but 7 years later, the tools/languages are changed in my school and they prefer java/C#. the languages are mere tools. What you need to get better is the fundamentals. e.g. in MIT people learns the algorithm fundamentals using python. e.g. Java may be good for web programming. but C/C++ are good for services and high performance applications. So it depends on your situations.

sarat
  • 1,121
  • 2
  • 11
  • 19
0

I started out with C++ in middle school. I picked up a copy of this book: C++ How to Program by Deitel and Deitel. This book is quite good.

Frankly there is no right or wrong answer here, I personally found that C++ was graspable. I learned it all the way to OOP ( I got tripped up on "this" which I now don't understand how I couldn't get that but whatever). Try it, don't get discouraged. If you get stuck, check out other languages and keep learning new ones. The idea is that as you see the same concept in 2-3 different forms you will understand them better. Like I said, the concept of the "this" pointer confused me but when I saw the same thing in Python (named self instead) it made sense to me right away because I'd understood it in C++. Do learn Java if you can as many colleges teach it. Do learn python or ruby as it's the language du jour and if you can explore more niche/new stuff like Clojure(and all the other lisps), Haskell, Scala...

nkassis
  • 451
  • 3
  • 5
-1

No. I'd start with Java or C#. If you want to learn C++, its probably easier after you've learned the basics, such as what is a class, how to do loops and forks(if, then statements), etc. It's much more important to learn how to look at a problem or a mathematical equation and program it than it is to figure out if you've released all your memory or whatever.

-3

Beginners need to appreciate 'programming' first. In my experience in training a class of beginners, they appreciated first what they understand the most. Like Python vs. C# they appreciate Python because its very high level and does not use symbols like C# does, meaning very near to human language, its very English. So I would recommend to learn programming from high level to low level.

LEMUEL ADANE
  • 167
  • 5
-3

It appears the assumption behind this question is "C++ appears so complex, will a 16 year old be able to pick it up as the first (computer programming) language?"

By the time we are 4 or 5, we pick up most of the constructs in the mother tongue, just with that much exposure to it through listening others speak it. Forming great sentences takes a life time, no question there.

C++ is sure a lot less complex/complicated than, say, most human languages. 16 year olds should sure be able to pick it up. Will they write great code with it? Got to wait and watch.

vpit3833
  • 1,330
  • 8
  • 11
  • 4
    Human languages can afford to have complicated syntax because if you gets the grammer or speling rong, people can still understand you. Not so with computer languages. – dan04 Feb 08 '11 at 01:10