Which to learn first C or C++?

S

Steve Pope

Bart said:
Steve Pope wrote:
There's a huge gap between 'memorized' and 'mastered'.

Sure, but the former is a prerequisite for the latter.
C is not a subset of C++. Lets see... reserved C++ keywords, void* not
being cast implicitly to other pointer types in C++, implicit
declarations of int returning functions in C, different semantics for
const objects, different rules for struct names and scope, character
litterals having type int in C and type char in C++, I could go on like
this...

It's a fairly limited list. But you're right, C isn't a true subset
of C++ due to this handful of necessary changes.
Not at all. C may actually be detrimental to your learning of C++ as it
may be necessary to unlearn things.

I disagree. Most of the things that would need "unlearning" would
only seep in if you did lots of development in C, forcing you to
use C-style coding practices. Simply learning the language would
not be detrimental to C++, and in fact is pretty necessary.

Steve
 
M

Marcus Kwok

Steve Pope said:
It's a fairly limited list. But you're right, C isn't a true subset
of C++ due to this handful of necessary changes.

A fairly comprehensive list of the differences between C(99) and C++
(excluding the "incompatible C++ features") can be found at:

http://david.tribble.com/text/cdiffs.htm

though it seems it hasn't been updated for C++03 or later (the document
is dated 2001-08-05).
 
B

Bo Persson

Earl said:
I cannot agree with that, not if you want to work in the practical
world, or at least in the world I work in.

Firstly, if you learn all of C++ then you are learning most of C
too.

No, you need to learn the core language, but can happily ignore the
ugly parts of the C library. If you don't know anything about
vprintf/sscanf/malloc/strcpy/memcmp/strdup/etc, you will be a much
happier C++ user.

Why learn the difference between abs(), labs(), llabs(), fabs(),
fabsf(), and fabsl(), when std::abs() will do?
You cannot ignore arrays and char pointers because we now have
vectors
and strings.

No, but you can defer learning it as long as possible. In "Accelerated
C++" this appears (reluctantly) in chapter 10, long after learning
about iterators, string, vector, and writing your own classes and
template functions.
In the real world you are probably going to have to maintain legacy
code, written in C-style. In the real world you will have to work
with
3rd party libraries with a C interface.

But why start at the ugly end when trying to learn a language?


Using a lightbulb is hard, because you apparently will have to learn
"all this electricity stuff" first. Lighting a candle seems much
easier. It's not!


Bo Persson
 
D

Default User

Bo Persson wrote:

No, you need to learn the core language, but can happily ignore the
ugly parts of the C library. If you don't know anything about
vprintf/sscanf/malloc/strcpy/memcmp/strdup/etc


There is no C function called strdup().




Brian
 
B

Bo Persson

Default said:
Bo Persson wrote:




There is no C function called strdup().

See how hard it is! :)

There actually was one on the last C compiler I used. Non-standard I
bet.

Here is something you don't have to learn either, if you go directly
to C++:

In the functions strtod(), strtof(), strtok(), and strtol(), d stands
for double, f stands for float, and l stands for long. What does the k
stand for?


Bo Persson
 
G

Greg Comeau

On a personal note, when I first decided to learn C++, I learned C
first. Then, when I tried to learn C++, I didn't like it. I'm not
really sure why, but I just preferred the C way of doing things, and I
expected C++ to be more C-like (as if it were a superset of the
language, which it really isn't), so I halted on my C++ progress. It
was only recently that I decided to get over myself and learn C++ (and
I like it now). I don't know if other people have experienced this,
but I just wanted to put it out there.

This is often a syndrome found in many learning situations.
Basically you get comfy (purposefully or not) and habitual
in a certain something, and then anything different is seen
as suspect or wrong or too complex or too hard, etc. in some ways.
Of course, everything does not work this way.
 
G

Greg Comeau

It can't possibly take you more than a couple weeks to re-learn
C to the point where you have the entire language memorized.

The OP never learned C to the point where the OP had the entire
language memorized, "all they did" was take a C at a community college.
That said, few people can "memorize" C in a few weeks, in fact,
most can't, and instead it takes years. Somehow we're talking
about different things I would imagine.
So I would do this, just to get it out of the way. Since C
is a subset of C++, and is the subset in which most/all procedural
code is written, you need to know C thoroughly to learn C++.

That's true to some extent, but not the whole picture.
Counterarguments on a number of aspects can be made for each.
 
F

Frederick Gotham

Earl Purple posted:
Firstly, if you learn all of C++ then you are learning most of C too.
You cannot ignore arrays and char pointers because we now have vectors
and strings.


I never said that. Arrys and char pointers are fully-fledged features of
C++.

In the real world you are probably going to have to maintain legacy
code, written in C-style. In the real world you will have to work with
3rd party libraries with a C interface.


If you are proficient in C++, you should be able to read C-style code
because you won't see any features that you've never seen before.

That seems rather strange, although they might complement each other.
C++ was designed to be backwardly compatible with C so that companies
could adopt it without throwing away all their existing and working C
code.

The compliment each other because:

(1) You know C++, a great language for doing all sorts of stuff.
(2) You know C, so you can write for tiny little microchips aswell.
 
I

Ian Collins

Gernot said:
I started with C and then tried to program C++. My C++ was C with
classes. Horrible. If I were you, I'd start with C++ directly. Then
you don't learn bad C habbits that you have to get rid of later.
String handling for one thing.
Agreed, I took a long time to get over 10 years of C and start thinking
about problems in a C++ way and that was in the days when C++ was little
more than C with classes.

What's more important than the feature differences between the two
languages is the mindset required to work in them. Learn C++ first and
learn to think as a C++ developer. The only drawback to this is you
will find pure C frustrating!
 
G

Greg Comeau

Learn C first.

People give all kind of reasons why learning C++ first is better. But
as someone who has jsut got into C++ after finishing K&R a month ago,
let me put the case for C.

1. C++ books either teach you a basic "C with classes" or are
incomprehensible without an understanding of C. Knowing C makes them
easier.

This comment is not pro or con, but to point out that
perhaps if that is the case that you are using the wrong C++ texts.
3. C is small. After 8 hours of K&R you will be able to download the
Linux kernel, read its code and understand it. C++ takes a lot longer
- it is way way bigger.

C++ is larger, but it is certainly not the case that most people
could read the LINUX kernel with only 8 hours of use of K&R.
4. C makes C++ possible. My first steps into C++ have been C programs
with STL string and vector thrown in. Almost against my will my code
is using classes just because it does make things easier.

But "equally" using things like C++ strings makes C easier :)
 
G

Greg Comeau

C++ is very powerful, but may be difficult to understand without prior
knowledge of C.

One doesn't learn a whole language en masse, but instead in parts.
Therefore, whether one learns C or C++ you're going to learn a subset
of either. That subset should be reasonable for either choice of
language.
Conceptually the biggest difference between the two is
OO programming, and generic programming. Both are topics that are not
explicitly tied to C++, but without knowledge of them you won't have
your C++ code fire on all possible cylinders.

Ok, so let's say this: programming is not equal to just learning
some language.
However, C++ is a subset of C (even Bjarne describes it that way, and
he should know), which implies that it is definitely good to have
knowledge of C before tackling OOP and generics in C++.
The more you use C++, however, the more you begin to 'forget' about C
libraries, and use C++ libraries instead. But that is a conscious
choice then, and the understanding of the value of strong type safety
and other C++ benefits is better when you know the alternative.

You probably meant the other way around, or that C++ is a superset
of C. Anyway, it's worth pointing out that some folks differ on this.
 
G

Greg Comeau

nope, C & C++ are different languages, they are really, very, very
different. my 4 months of experience with both of these langugaes has
convinced me enough to not to believe 90% of book authors (IFF, you
want to learn "Pure C++" a.k.a "Modern C++"). C was chosen as an
"inspiration" (as a "base") to create C++ & their "designs" & "ways"
of solving problems are completely different. at least this is what i
have found.

C is more than just inspiration for C++, as C++ is literally
built upon it, but yes, at some point, that does mean differences
of various natures materialize.
 
D

Default User

Greg said:
C is more than just inspiration for C++, as C++ is literally
built upon it, but yes, at some point, that does mean differences
of various natures materialize.

I think "approximate subset" or something like that to describe C is
OK. Right now, the differences between C99 and C++ are somewhat greater
than between c90 and C++, but still you can write a very large set of
programs that are syntactically and semantically identical in either
language, although you may need some some less than optimal constructs.



Brian
 
G

Greg Comeau

If you are proficient in C++, you should be able to read C-style code
because you won't see any features that you've never seen before.

This assumes C90, not C99.
 
G

Gernot Frisch

What's more important than the feature differences between the two
languages is the mindset required to work in them. Learn C++ first
and
learn to think as a C++ developer. The only drawback to this is you
will find pure C frustrating!

Well, I use C for Microprocessors, and these programs usally are so
small that C is not really frustrating. VisualBasic would be ;)
 
E

Earl Purple

<snip stuff>

I never said that you had to learn C first, I said that you can't not
learn C at all and learn only C++ (as what I quoted above).
No, but you can defer learning it as long as possible. In "Accelerated
C++" this appears (reluctantly) in chapter 10, long after learning
about iterators, string, vector, and writing your own classes and
template functions.

I have not read Accelerated C++ nor would it be possible for me to
judge any C++ book for beginners by reading it now because I know the
language already. The best person to judge a book that teaches a
language is someone who doesn't know how to program at all. Someone who
finds the concept of a for-loop complicated and has to be explained the
concepts of parameter passing by value and by reference (whatever means
you use for "by reference").
But why start at the ugly end when trying to learn a language?

Actually if I were really going to teach people C++ I would try to
create a whole framework with a cool GUI (possibly written in another
language) and they would be writing libraries.

One thing I have pretty much never used in my whole C++ programming
career is cin. Console apps look like they belong 20 years ago and even
then there is no way to intercept the key presses so when you ask them
to enter a number, you can't "ignore" invalid key presses. Now give
them their first Java course or C# under .NET and they'll think "cool -
cutting edge technology". C++ has to be taught for its strengths, i.e.
writing libraries or processes that run in the background.

Yet every C++ beginner I have encountered is writing console apps and
struggling with cin.
Using a lightbulb is hard, because you apparently will have to learn
"all this electricity stuff" first. Lighting a candle seems much
easier. It's not!

And to the one who said "turn on the switch", that is what you want to
do. Teach them to make different types of lamps and then plug it in to
the existing technology. Make it look cool and modern and you'll get an
interest.
 
F

Frederick Gotham

Earl Purple posted:
I never said that you had to learn C first, I said that you can't not
learn C at all and learn only C++ (as what I quoted above).


Over 95% of people use C++ perfectly well without having programmed in C.

Yet every C++ beginner I have encountered is writing console apps and
struggling with cin.


That's because you can test out algorithms real easily with console
applications.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top