Re: C versus C++
On 2007-07-14 16:40, email@example.com wrote:
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'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.
I have not looked one any DB code but most OS code I've seen have been
quite object oriented, with structs being the objects and the functions
that operate on them the methods, and there are both constructors and
destructors. However due to the lack of OO support in C all data is
public and the methods are not members, and constructors have to be
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++.
I'd say that they are programmed in C because either they have to be
part of an OS written in C (for the FS) and because if something is
written in C it can be called from almost any other language (for the DB
application). That and the fact that most DB projects are either decades
old or derived from code that is, rewriting something that works just to
change the language is usually not a popular idea.
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.
Having said that I do recognise the fact that all problems are not best
solved with an OO design, procedural programming also have it's place.
Personally I find that you get the best effect when you mix a couple of
styles (templates and OO is a good example).