J
JohnQ
I would say that, in general, you don't need to learn C before
learning C++. In fact, I would go as far as saying that there's
really no reason to learn C at all. Most programming tasks are better
handled in C++, in my opinion. But there is one significant exception
I think.
I'm sure there are many people here who will disagree with me, but it
seems to me that the C programming style is somewhat more well suited
to database and/or file-system programming than C++. Of course, you
*could* program a database or a file system in C++, but in practice,
it's mostly done in pure C.
The reason has nothing to do with language capability. As a superset
of C, C++ is more than capable of doing anything C can do, obviously.
But C++ encourages a certain, "style" or "mindset" or programming,
which is totally different than C style programming.
C++ programmers tend to think in terms of objects - non-permanent,
dynamic data structures which are stored in memory. C programmers,
however, tend to think in terms of raw data: pointers to contiguous
memory blocks, structs, etc. And objects don't always translate well
to concepts involving permanent storage, like disk blocks, etc.
That's why major file systems like XFS, reiser, etc., as well as
database systems are usually programmed in C, even though they *could*
just as well be programmed in C++.
Just to avoid confusion: I'm *NOT* saying that C is better than C++
for anything. I'm saying that, in practice, C-style programming
usually lends itself better to programs which manipulate raw data on
disk, such as file-systems or databases, rather than C++ style
programming, which usually revolves around objects in memory.
By saying "C-style" and "C++ style" you are making the assumption that C++
developers have either forgotten how to engineer stuff since they moved from
C to C++ or that they grew up with C++ and therefor never knew how to in the
first place. The latter scenario is more plausible than the former. It's not
a question of language-associated-"style" but rather a question of developer
knowledge/skill. Just knowing the language at a high level is not enough.
HOW one uses it is important too.
I wouldn't say that "C++ encourages a mindset" but rather that C++'s vast
complexity makes it difficult for one to get their mind around it,
especially the new developer. It's, of course, up to the developer to
"figure out C++" before applying it. Indeed, C++ isn't going to hold your
hand and enable you automagically. The issue you raised (the hindrance to
the uninitiated, IOW IMO) seems to be directly related to the decision to
make a struct and a class the same. Doing so obscured the "styles" you put
forth above. Of course, you don't have to fall prey to it. You can still
program either way but don't expect to get compiler warnings and such to
keep from shooting yourself in the foot at the low level design (not in
C++'s current incarnation that is).
(The people here who responded to your post and thought it was a C vs. C++
flamewar post obviously missed your point contained within, but you did help
that along by titling the original post "C vs. C++").
John