Why C and not C++?

Why all this work coercing C into objected-oriented code, a form it wasn’t really designed for? This is a personal question spanning well over a decade of watching the C++ go from having no specification, to having a standard specfication not implemented anywhere, to having various parts of the standard implemented in various ways on various platforms, none of which completely met my needs at the time.

In all of the following, everything I write represents my perception of the ground truth at the time. In places, this could mean that I understood the situation incorrectly, and that the truth is other than what I believed at the time. However, every decision I made was based on at least an 8 hour days worth of research into the issue. Given that my focus at the time (and now) was on writing applications for civil engineers on the Win32 platform, I regard these decisions as valid within the context of the time they were made.

Brass tacks

Here’s a list of some of the issues, in no particular order:

  1. Microsoft Development Studio (MS Dev) through V6 did not support the STL. I am still using V6. I hope to change to V8 fairly soon, but that requires enough time in non-billable overhead to make it worthwhile. In other words, upgrading is at the expense of time I could be billing elsewhere, literally, money out of my pocket. The case for remaining in C is strong.
  2. Microsoft really tried to push people into MFC, which works it's magic by through very non-standard (thus non-portable) means. I tried it, I didn't like, back to C.
  3. C++ syntax appears arcane to me. Given the above two points, dealing with obtuse syntax made me feel like I was wasting my time.
  4. At the time, Java fulfilled my OO aspirations.
  5. Template capability was poorly supported on most platforms, and bloated on platforms (gcc *cough*) that it was supported on. The situation now is supposedly much, much better.
  6. Linking issues... I don't think I need to say any more.
  7. Other issues as I recollect.

Note that I kept coming back to investigate the state of C++ on both gcc and MS Dev over the course of many years. I collected at least $200 worth of dead tree C++ programming books (including Stroustroup) during that time. My desire was pretty strong, but the cost/benefit just didn’t make my numbers.

Current situation

At this point, all the above points have been dealt with very well. Microsoft tools now support the STL (some would argue not very efficiently, but they are supported now). Templates are well-implemented on all important platforms (i.e., gcc). As I am starting into a new coding project to build a library API over a very thick file format specification using the principles I am outling in this series, I keep thinking “This would probably be easier in C++, provided everything worked as advertised.” The upshot of all this is that Object Oriented C is not difficult to write by anyone with a working knowledge of C and a little experience with the principles of OO desgn. The techniques of OOC have a place in the toolbox of any developer working with compiled languages, and can be profitably employed on small to medium sized code bases.

Going forward

Although the above account sounds extremely pessimistic, during the time period covered in the above account (over 10 years), I wrote a small amount of C++ code on the cygwin gcc platform, productively using both elements of the STL and templates. Modulo a certain amount of aggravation induced by mastering the syntax and compilation issues, I really liked it. It wasn’t as easy as Java to write, but compiling into an executable is more useful than compiling to byte code for my purposes. For small new projects, or for coding up test cases of algorithms, I plan on choosing C++ in the future.


Tags