Fog Creek Software
Discussion Board

c++ before c??

i was bored today and i started browsing through some college websites and looked at their computer science cirriculum(sp).  I was suprised to see that for many universities, there first programming class is c++, rather than c.  And c is taught in a higher-level course.  I personally think it should be the other way around.  what are you thoughts??


mike johnson
Tuesday, August 5, 2003

It doesn't matter.  Despite the similarities, you generally teach C++ and C as if they are two completely different languages.

Flamebait Sr.
Tuesday, August 5, 2003

I would actually say learn some C first.  You don't have to learn the standard lib, since the C++ standard lib is better, but C is a small language and just learning stuff like pointers and null-terminated strings will help you in C++.

Without the C background, I feel that C++ seems like 100 different arbitrary rules, each with 10 exceptions in practice.  If you have the C background, then you can at least understand why the rules are the way they are.  Otherwise you're just memorizing.

Tuesday, August 5, 2003

You can't even have this discussion until you've read Stroustrup's "Learning Standard C++ as a New Language" at so do that now.

Tuesday, August 5, 2003

The only reason they teach like that is because they want to teach freshmen data structures and the like. And back in the days C didn't have as much OOP (this is not the case now) and even today it has slightly different way of doing some of the things C++ would do. OOP goes with the territory of teaching data structures so they would try to tackle C++ without hurting the little ones with pointer mathematics. But then the grades come in and you realize maybe they should have started with C.

Li-fan Chen
Tuesday, August 5, 2003

Seems to me that one could teach a (minimal) subset of C++ in an introductory class, and it might be easier than C for a novice.

For simple CS 101 tasks like "Prompt the user for ten integers, and calculate the mean", using cout and cin is probably less confusing than fgets, sscanf, and printf.

I think BASIC was a pretty good first language, really. I think that any language/environment where your first few programs have a majority of lines that don't actually contribute to doing useful work, is a bad teaching tool.

10 Print "What is your name?"
20 Input $name
30 Print "Hello, ", $name, "!"

#include <stdio.h>
    int main(void) {
    char name[80];

    printf("What is your name?\n");
    fgets(name, 80, stdin);
    printf("Hello, %s!\n", name);

Leaving aside the number of things you have to understand to even comprehend this program, it doesn't even do (quite) the same thing. It turns out that simply prompting the user for a string and reading it in is "tricky" in C.

Sure, you could "simplify" this program by using gets(), but then you'd eventually have to tell the students why they should never actually use gets() in a real program.

Someone else can post a "good" C++ version, but it'll only be a little better.

Mark Bessey
Tuesday, August 5, 2003

Hmm. My last post seems to have wandered off-point a bit. What I was trying to say is that C is a TERRIBLE language for teaching. A properly-selected subset of C++ might be better.

(but really, an interactive, interpreted language should be everybody's introduction to programming - whether it's Scheme, BASIC, Smalltalk, or what isn't as important)

Mark Bessey
Tuesday, August 5, 2003

My introduction to programming was JavaScript. It was great: interpreted, simple, object friendly (but also procedural), and you can see the results of what you're doing instantly in a browser.

Unfortunately, thanks to some truly lousy browser DOM implementations, JavaScript has gotten a bum rap as a language, but I think it's actually a very nice language.

And there are a few standalone JS interpreters out there, for when a person is ready to graduate from the browser environment.

The worst thing about JavaScript is that there are very few useful objects in the runtime, and there is no way to import modules, so you can't actually DO ANYTHING with JavaScript unless you're scripting a browser (or some other application that exports its DOM to a JS interpreter (which is pretty rare)).

Benji Smith
Tuesday, August 5, 2003

It's quite a bit less messy in C++, since with the STL you don't have to know anything about arrays, pointers, or memory allocation just to get a string.  Tell me this is not readable to your average programming newbie (with only a small amount of explaining required):

#include <iostream>
#include <string>

using namespace std;

int main ()
.      string myName;
.      cout << "What is your name? " << ends;
.      getline(cin, myName);
.      cout << "Hello, " << myName << "!" << ends;
.      return 0;

Tuesday, August 5, 2003

What universities teach c++ before c?

Tuesday, August 5, 2003

Mine did.... Sorta.

Java first, then C++, and from there, you were expected to pick up whatever language was used in the class... which was generally of the set {C,C++,Java,ML,Lisp}

Flamebait Sr.
Tuesday, August 5, 2003

If you want to learn C++, you should learn C++, if you want to learn C you should learn C. Just as if you want to learn French, you learn French and if you want to learn Spanish, you learn Spanish.

C++ is decently capable of OOP which is, I'd say, a much better way to learn to program that traditional block based techniques. In fact I'd go as far as to say that learning to program in C is actively detrimental to learning to program in C++ because you have to learn a whole new way of solving problems.

Mr Jack
Wednesday, August 6, 2003


The University of Michigan made the switch a little over 5 years ago, right before I graduated.

I started with C (ok, actually Pascal, but that was when I was a physics major), but really didn't appreciate some of the finer point(er)s until I took some courses in basic computer architecture and worked in assembly. For an intro to data structs and algorithms I think C++ or Java would have been fine.

Wednesday, August 6, 2003

*  Recent Topics

*  Fog Creek Home