[wplug] relevance of C for Apps

Tim Lesher tim at lesher.ws
Wed Oct 6 10:59:38 EDT 2004


C really isn't that much faster in most application cases than C++
(there are some exceptions).  There was a time when an extra pointer
indirection (forr virtual methods) was costly, but that just isn't the
case for most situations nowadays.

Where C++ really beats C is in bugproofing and maintainability.  A
number of techniques ("Resource Acquisition Is Initialization"
methods, auto_ptrs, etc) help significantly to prevent memory leaks;
C++ has useful abstractions that make it easier to do object-oriented
programming than in C, and templates and code encapsulation make it
easier to reduce the amount of code you have to keep in your wet grey
cache at one time.

C++ is definitely a more complex language that C, and it's continuing
to evolve faster than C.  C99 notwithstanding, the standard library
and STL are far bigger changes from C programming to C++ programming
than anything in the language itself, although there are a lot of
people that call themselves C++ programmers, yet have little to no
knowledge of them--they use C++ as "C with better type checking".

The evolution of assembly language C to C++ to higher-level languages
like Python and Java is, I think, a result of the increasing
complexity of software and the not-increasing complexity of the human
brain.  I can write (for example) a Python app to do a task in around
a fifth of the time I'd use to write the equivalent in C++, and I
could write the C++ app in about half the time it would take me to
write the C version (even though I have more experience in C than in
C++, and far more in either of them than in Python).  In some cases,
the python app will run noticably more slowly than the C or C++ app,
but I'm willing to trade machine time for my time in almost all cases.

Anymore, the only time I drop down to C is when I'm writing a library
of some kind.  The lack of a decent C++ binary standard means that
using C++ libraries across languages is still a genuine pain; it's
usually easier to write the library with a C API and wrap the C API,
if desired, with a C++ wrapper on the application side.  C++ just
isn't there yet.

I used to be a "get the best machine performance at all costs" bigot,
but looking at the bigger picture, my time is generally worth more
than the computer's.  Naturally, this sentiment can be taken too far,
but my decision tree is usually "code it up in python, see where the
bottlenecks are, then rewrite those in C or C++ as needed."

-- 
Tim Lesher <tim at lesher.ws>
http://www.lesher.ws



More information about the wplug mailing list