Re: C++ Frequently Questioned Answers
On 1 Nov, 18:36, Yossi Kreinin <yossi.krei...@gmail.com> wrote:
One particular thing that AFAIK applies almost always: low-level work
is better done in C than C++. I speak from lots of experience (but it
doesn't matter - what matters is whether my points in the FQA convince
you or not). By "low-level", I mean "when your resources are really
scarce" (compared to the "size" of the problem).
Hmm, this is interesting. I recently did some work on a java project
where I had to interface to a third-party library written in C. I used
SWIG to create a JNI wrapper which has enabled the project to be
rewritten in java. There was poor encapsulation in the lib and various
other issues so I wrote a layer above this lib. I chose to write that
layer in C which is then SWIG'd. But the reason was not due to the low
level work. It is true that some might consider the work to be low-
level, e.g use of UNIX pipes, multiple socket select, POSIX condition
variables and so on but there are several C++ libs that provide nice
wrappers for these (ACE, Boost, Poco etc etc). I didn't use them
because the project was trying to get rid of C++. I managed to keep
the wrapper small enough that the project now has no C++ complexities
because there is no C++. Using them would have made things smaller and
easier in some places.
For example where I used POSIX mutexes it would have made for shorter
simpler C++ if I used RAII. Instead in C I had to be more careful and
tended to use goto's to jump to cleanup code on errors. This made the
code longer and of course, meant was using the dreaded goto. This lost
opportunity to use RAII is probably what David Abrahams was referring
to when he said his code was typically shorter and simpler in C++.
So I wonder why you would chose C. I did because of special project
needs, what are your reasons please? Why is the scarcity of resources
an issue here?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]