how relevant is C today?

David Rasmussen david.rasmussen at gmx.net
Sun Apr 9 15:52:32 EDT 2006


Mirco Wahab wrote:
> 
> I would say, from my own experience, that you wouldn't
> use all C++ features in all C++ projects. Most people
> I know would write C programs 'camouflaged' as C++,
> that is: write clean & simple C - and use some C++
> features e.g, class bound methods for interfaces -
> but no inheritance at all (use compound objects) and
> no exceptions (handle errors 'the olden way').
> 

Of course. C++ is a hybrid language by design, not only an object 
oriented language, not only a language with exceptions, not only a 
language with compile time metaprogramming etc.

You don't have to use all the features of C++ to make a real C++ 
program. Even for writing C programs, C++ is still a better choice (in 
my opinion). If you want to, you can keep things "simple", and plain 
C-ish, and still benefit from better type safety etc.

In my everyday work, I am forced to use a C90 only compiler, and 
everyday I miss some C++ feature that wouldn't make my program any more 
complex, quite the opposite. These are features like "const", no default 
extern linkage, more typesafe enums etc. You can put upon yourself to 
program in a C style, but whenever you miss something, you can always 
wrap that up behind an abstraction such as a class etc., and still 
maintain C-like semantics.

Say I wanted an Ada-like integer type that only runs from 1 to 100. I 
could make such a beast in C++, and then use it just as an ordinary int 
in my C style program. I could even make this beast _be_ an ordinary int 
in release builds when I was sure (yeah right) that the code was 
bugfree. This gives expressibility and preciseness in specification. You 
let the compiler do the work for you. And you still maintain 
performance. You can't do this in C at all. And there are a million more 
examples.

In practice, the combination of Python and C++ covers most of what I 
need to do in most situations. But I still wish that C++ offered a lot 
more of those zero-overhead features that it might as well offer, that 
the compiler just as well can do. It could learn from Ada in this regard.

/David



More information about the Python-list mailing list