C or C++ do you prefer to program?

C or C++ do you prefer to program?

Post by David Schw » Fri, 11 Jul 2003 19:53:25

Whichever works best for the task at hand.

If it's a project that will take less than hour and doesn't require
using a lot of previously written code, C usually wins hands down. (Though
most programmers would probably use C++ anyway, just not really use it.
Think of it as C with C++ strings and/or other minor conveniences.)

If it's a massive project that requires reusing a lot of existing code,
must be maintainable, and requires dozens of cooperating programmers, C++
wins hands down.

In-between, it's largely a matter of preference.


C or C++ do you prefer to program?

Post by mru » Fri, 11 Jul 2003 20:06:21


C. C++ just adds trouble.

Ms Rullgd


C or C++ do you prefer to program?

Post by Lorinczy Z » Fri, 11 Jul 2003 20:38:30

Very good question to start a never-ending flame-war ;)

Let me ask an other question:
which language do you know: C or C++ or both or none?

C or C++ do you prefer to program?

Post by mtsou » Fri, 11 Jul 2003 22:09:51

I know both but not that much.
I will soon start a project and I will like to hear
the opinions of professionals.
I have no-intention to start a flame-war so please don't
blame :-)


C or C++ do you prefer to program?

Post by Chuck Dill » Fri, 11 Jul 2003 23:57:49

I suppose I prefer C but what I like isn't relevant to what I do. When
I evaluate a job my personal preference has a weight factor of just
about zero. In fact, I'm more likely to want to select a new
technology than focus on what I 'like'.

Don't fall in love with any technology.

-- ced

Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.

C or C++ do you prefer to program?

Post by Robert Syn » Sat, 12 Jul 2003 08:31:48

Ususally C, if only to prevent library-linking nastiness, vague guilt
over not using OO properly, etc. :)

C or C++ do you prefer to program?

Post by Peter Ammo » Sat, 12 Jul 2003 13:44:21

I like C in part because it's the common denominator. If there's some
task you want to perform, someone somewhere has written a C library to
do it. You can maybe get it to work with C++ if you tweak it a lot, but
no guarantees.


C or C++ do you prefer to program?

Post by Peter Ammo » Sat, 12 Jul 2003 17:04:44

ianni Mariani wrote:

Those aren't examples of eliminating errors that people commonly make
with C. In any case, C++ introduces lots more opportunities for errors.

As for templates, they're a pretty shoddy implementation of a great
idea. I like the ML type-inferencing model of generic programming myself.

I'm not convinced that those structures are worth the tradeoff. If
nothing else, you have to look at stuff like "`void std::vector<_Tp,
_Alloc>::push_back(const _Tp&) [with _Tp = int, _Alloc =
std::allocator<int>]'" when you get a type error.

I did my best to write in the language as the designer(s) intended for
them to be written in. I used essentially the same algorithm for each
of them. I guess the moral is that you have to write poor C++ (i.e.
avoid the STL) to get good performance.

How many languages can YOU name that have operator overloading?

Pretty much anyone looking at that code would get the wrong idea of what
it does.

RIP useful type safety.

This is true. C++ has very inexpensive classes.

I agree that templates are powerful, but I think the syntax and
difficulty of debugging them compromises their utility.

This strikes me as pretty silly. Instead of having to implement
to_string(const SomeType_t & val), you have to implement ostream &
operator<<(ostream &, const SomeType_t & val), and they do essentially
the same thing. You haven't saved any real work. I don't think that
feature is worth the sheer counterintuitiveness of C++.

(And besides, overreliance on the static types of variables causes
problems. I've lost count of the number of times I've been asked why
cout << toupper('a') doesn't output 'A'.)

There are languages where you could make a *truly* generic to_string
function, where the function could look up the positions and types of
the instance variables of the class (at runtime, no less) and construct
a string based on those. That's the sort of feature that I'd be happy
to endure a steep learning curve to get.



C or C++ do you prefer to program?

Post by sant » Sat, 12 Jul 2003 22:02:24

i seem to like c++ a lot and never usually use c unless the task at hand is
so simple that it really doesnot matter.

OOP is a concept that is indeed worth its name


C or C++ do you prefer to program?

Post by Gianni Mar » Sat, 12 Jul 2003 23:29:27

eter Ammon wrote:

So ?

Yes, this can be the case sometimes. The STL may get in the way.


Operator overloading is an integral part of C++. If std::string does
somthing wierd with operator +=, then smack the guy who wrote
std::string and all those who voted to adopt it. You just can't do some
very cool things with C++ without operator overloading.

lay this down to experience. When I wrote my first printf( ...) in C++
I had similar woes. So, what ! You'll not make this mistake again.
Chalk it off to learning curve.

how ?

Yes, debuggers up until recently have proved near useless. All the more
reason to have a good set of test cases.

Heck ... no one stopped you from writing a one liner:

cout << foo << 22 << endl;

fair comment. This requires another shift of thinking away from C.

There are a few more things I'd like to see as well. Does that mean you
stick with C until there is a perfect alternative ?



C or C++ do you prefer to program?

Post by mtsou » Sun, 13 Jul 2003 00:54:20

I have that feeling too, but C++ has also some advantages:
- STL (you get a lot of tested functions and structures)
- ACE library for network programming

What do you think about those?


C or C++ do you prefer to program?

Post by felix zasl » Sun, 13 Jul 2003 02:35:38

That is absurd !!! STL can produce faster code then C equivalents
sometimes. For example std::string class can take advantage of
reference counting and avoid copy where and in C you usualy have to make
copies right away and cant do it lazily like in C++.

Your little bench is not meaningful sorry.
When you do a bench next time dont forget to
1. tell us the compiler version
2. tell us the Operating System, libstd++ and libc versions.
3. use the clock() function to make measurements
4. run many iterations to get good statistical results.
5. write the program optimaly. ex dont use formated io when unformated
can do just as fine.

C or C++ do you prefer to program?

Post by felix zasl » Sun, 13 Jul 2003 02:43:32

Most libraries available in unix are C libraries
C++ works with C libraries just fine

if the author of C library forgot to include this in the header
#ifdef __cplusplus
extern "C" {
#end if

You can simply put this in. thats all to it !
extern "C" {

C or C++ do you prefer to program?

Post by Fritz » Sun, 13 Jul 2003 02:57:18

"Which is better, Babylon 5 or Star Trek?" Find the answer to this FAQ


This is the troll that never ends,
It goes on and on my friends.
Some people starting singing it
Not knowing what it was
And they'll go on singing it forever just because
This is the troll that never ends...

To reply, translate domain from l33+ 2p33|< to alpha.
4=a 0=o 3=e +=t

C or C++ do you prefer to program?

Post by Peter Ammo » Sun, 13 Jul 2003 11:25:10

ianni Mariani wrote:

It turns debugging into a process of trial and error, at least until you
learn to read C++-error-ese.


I agree that operator overloading is fundamental to C++ and without it,
C++ would be much less cool. The problem here was related to both
operator overloading and being type unsafe.

Yup. C has its warts and you just lanced one.

I have. But I run into some new mistake new almost every time I try to
program with C++. Meanwhile, I'm feeling happily productive in other
languages with much less time invested in learning them, so it's
becoming harder and harder to justify C++. Your mileage may vary.

The integer literal 22 was implicitly converted to a char because
std::string had overloaded += for a char. I can't imagine that many
people ever want to append a character to a string when they've
specified it using its decimal representation, so i consider this to be
a type error.

I definitely agree with that! (I wish I lived it more often!)



I guess it does.

Well, no, but it means I choose alternatives to C++ more often than not.