C or C++?

Kevin D. Clark clark_k at pannaway.com
Fri May 27 17:49:01 EDT 2005


Jim Kuzdrall writes:

>     C++ versus C is my quandary.  Can anyone give me good reasons for 
> choosing one over the other in this case.  Opinions are welcome, but I 
> must have a list of reasons ready if my choice is questioned.

Pros for C++:

  o easier to work with in a OOD/OOP way

  o STL and BOOST and ACE are nice.

  o if you're disiplined, you can take advantage of code-reuse.

  o objects that wrap around things like locks make for cleaner,
    easier to maintain code.  I use "goto" a lot in procedural code to
    duplicate this same effect.

  o If used properly, in general, C++ seems to scale better to larger
    projects. 

Cons for C++:

  o  hard to justify if you're just going to write C/procedural code
     anyways

  o  code bloat can be an issue (for example, because of templates).

  o  you need to be an experienced C++ programmer in order to
     understand which features are prudent to use in your environment.

  o  places more stress on your development tools.  For example, what
     happens if your debugger doesn't like dealing with two functions
     named "foo"?

  o  You're probably going to want to avoid calling any hard realtime
     code from C++.  What happens if one of your methods throws an
     exception?  Etc.

  o  I find that a lot of low-level code such as sockets stuff, serial
     code, realtime code doesn't really lend itself much to OOP
     anyways.


Pros for C

  o  combines the flexibility of assembly language with the power of
     assembly language. 

Cons for C

  o  combines the flexibility of assembly language with the power of
     assembly language. 




Issues that others have raised that I find to be kindof bogus:

  o  type safety -- prototypes and "const" are available in C; C++
     doesn't give you very much more of an advantage here.  

  o  portability -- in my experience, C++ code isn't more portable
     than C code.



I wouldn't hesitate to start a project in either C or C++.  If the
project was going to be pretty large, with a lot of programmers, and
it seemed to lend itself to an OOP style, I'd go with C++.  If I
wanted the  program to maximally portable, if the program wasn't going
to be spectacularly huge, and I was going to be doing more low-level
coding, I'd use C.

Just my opinions,

--kevin
-- 
If you want to program in C, program in C.  It's a nice language.  I
use it occasionally...   :-)
     --Larry Wall in <7577 at jpl-devvax.JPL.NASA.GOV>



More information about the gnhlug-discuss mailing list