[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Is c++ only better c ?

Pawel_Iks

10/24/2008 9:27:00 AM

I've read somewhere that c++ is something more than better c ... then
I talk with my friend and he claimed that c++ is nothing more than
better c ... I tried to explain him that he was wrong but I forgot all
arguments about it. Could someone told something about it?
48 Answers

Maxim Yegorushkin

10/24/2008 9:55:00 AM

0

On Oct 24, 10:27 am, Pawel_Iks <pawel.labed...@gmail.com> wrote:
> I've read somewhere that c++ is something more than better c ... then
> I talk with my friend and he claimed that c++ is nothing more than
> better c ... I tried to explain him that he was wrong but I forgot all
> arguments about it. Could someone told something about it?

Some actually consider C++ to be worse than C: http://esr.ibiblio....

--
Max

James Kanze

10/24/2008 1:58:00 PM

0

On Oct 24, 11:55 am, Maxim Yegorushkin <maxim.yegorush...@gmail.com>
wrote:
> On Oct 24, 10:27 am, Pawel_Iks <pawel.labed...@gmail.com> wrote:

> > I've read somewhere that c++ is something more than better c
> > ... then I talk with my friend and he claimed that c++ is
> > nothing more than better c ... I tried to explain him that
> > he was wrong but I forgot all arguments about it. Could
> > someone told something about it?

> Some actually consider C++ to be worse than
> C:http://esr.ibiblio....

You'll find some idiot to defend just about any position. (Not
that all people who are critical of C++ are idiots. But the
intelligent ones don't like C either; the real problem with C++
is that it inherits too much from C.)

C++ definitely improves C. It also adds a lot of things which
support idioms which aren't supported in C. I suppose that you
could call support for OO, or support for generic programming,
an "improved" C, but IMHO, that's stretching it. I suspect,
however, that what the friends of the original poster were
criticizing is C++'s C-ness; it does inherit a number of
problems (e.g. declaration syntax) from C.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

osmium

10/24/2008 2:27:00 PM

0

"Pawel_Iks" wrote:

> I've read somewhere that c++ is something more than better c ... then
> I talk with my friend and he claimed that c++ is nothing more than
> better c ... I tried to explain him that he was wrong but I forgot all
> arguments about it. Could someone told something about it?

IMO, the best place to get an answer for that kind of question is in the
link below..

http://www.research.att.com/~bs/b...


Chris M. Thomasson

10/24/2008 7:45:00 PM

0


"James Kanze" <james.kanze@gmail.com> wrote in message
news:ded8588f-baa2-4229-a17e-b658a95105fc@34g2000hsh.googlegroups.com...
On Oct 24, 11:55 am, Maxim Yegorushkin <maxim.yegorush...@gmail.com>
wrote:
> On Oct 24, 10:27 am, Pawel_Iks <pawel.labed...@gmail.com> wrote:

> > > I've read somewhere that c++ is something more than better c
> > > ... then I talk with my friend and he claimed that c++ is
> > > nothing more than better c ... I tried to explain him that
> > > he was wrong but I forgot all arguments about it. Could
> > > someone told something about it?

> > Some actually consider C++ to be worse than
> > C:http://esr.ibiblio....

> You'll find some idiot to defend just about any position. (Not
> that all people who are critical of C++ are idiots. But the
> intelligent ones don't like C either; the real problem with C++
> is that it inherits too much from C.)

> C++ definitely improves C. It also adds a lot of things which
> support idioms which aren't supported in C. I suppose that you
> could call support for OO,

[...]

You can get "fairly clean" abstract interfaces in C; something as simple as;
quick code scribbling - may have typo:


IShape.h
--------------------------------------------
struct IShape_VTable {
void (*IObject_Destroy) (void*);
void (*IShape_Draw) (void*);
/* ect... */
};

struct IShape {
struct IShape_VTable* VTable;
};

#define IObject_Destroy(Self) ( (Self)->VTable->IObject_Destroy((Self)) )

#define IShape_Draw(self) ( (Self)->VTable->IShape_Draw((Self)) )




That all the infrastructure. Now to create actual shapes...

Circle.h
--------------------------------------------
extern struct IShape*
Circle_Create(
/* ... */
);




Circle.c
--------------------------------------------
#include "Circle.h"
#include <stdlib.h>


static void Circle_IObject_Destroy(void*);
static void Circle_IShape_Draw(void*);


static struct IShape_VTable Circle_VTable = {
Circle_IObject_Destroy,
Circle_IShape_Draw
};


struct Circle {
struct IShape IShape;
/* ... */
};


struct IShape*
Circle_Create(
/* ... */
) {
struct Circle* Self = malloc(*Self);
if (Self) {
Self->IShape.VTable = &Circle_VTable;
return &Self->IShape;
}
return NULL;
}


void
Circle_IObject_Destroy(
void* IObject
) {
free(IObject);
}


void
Circle_IShape_Draw(
void* IShape
) {
struct Circle* const Self = IShape;
/* ... */
}





Now, finally we can use the Circle via. the abstract interfaces IShape and
IObject:

main.c
--------------------------------------
#include "Circle.h"


int main(void) {
struct IShape* Shape = Circle_Create(/* ... */);
IShape_Draw(Shape);
IObject_Destroy(Shape);
return 0;
}




There... simple!

;^D

Juha Nieminen

10/24/2008 9:44:00 PM

0

Maxim Yegorushkin wrote:
> Some actually consider C++ to be worse than C

In my personal opinion those are delusional prejudiced people who
suffer from a huge resistance of change. The claim is completely
ridiculous for two reasons:

1) Anything you can do in C, you can do in C++.
2) You are not forced to use anything extra in C++ if you don't want to.

The only way C++ could even theoretically be worse than C would be if
you were *forced* to do something in C++ which you don't have to do in
C, and this something is detrimental to the program. However, C++ does
not force you to do *anything* you couldn't do in C as well. Anything
you can do in C, you can do in C++. Thus the very claim that "C++ is
worse than C" is plain BS.

For example one could argue that, let's say, "Java is worse than C",
and there can plausibly be rational reasons for this claim because in
Java you are forced to do things rather differently than in C. For
example in Java you are *forced* to write classes, which you don't have
to do in C. Java does not support everything C supports (at least not
verbatim).

Now, if the claim was changed to "what C++ adds to C only makes the
language worse", it could make even a little bit of sense. Of course
this claim is also complete BS, but at least it's a more logical and
sensible statement.

The hilarious thing about C++-hating C-hackers is that it's rather
easy to make them squirm: Just challenge them to implement a small
simple program which handles dynamic memory, to compare the simplicity
and safety of the equivalent C and C++ implementations. Then just sit
back and be entertained by the (often surprisingly) imaginative ways
they will try to cheat their way out of the problem (because they really
*don't* want to compare C and C++ implementations of the problem
side-by-side).

James Kanze

10/25/2008 8:41:00 AM

0

On Oct 24, 11:43 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> Maxim Yegorushkin wrote:
> > Some actually consider C++ to be worse than C

> In my personal opinion those are delusional prejudiced people
> who suffer from a huge resistance of change. The claim is
> completely ridiculous for two reasons:

> 1) Anything you can do in C, you can do in C++.

That's not true:

int
main()
{
someFunction( 42 ) ;
return 0 ;
}

is a perfectly legal C program (supposing someFunction defined
in some other translation unit), but not a legal C++ function.
Among the things that you can do in C, but not in C++, are:

-- not declare external functions, then call them with the
wrong number or type of arguments,

-- assign a void* to a typed pointer, regardless of type, with
no explicit conversion to warn you that something extremely
dangerous is going on.

There are probably others, but these two come immediately to
mind.

Whether these possibilities can in any possible way be
considered an improvement, I leave to the judgement of the
reader.

In C99, there are a couple of more things you can do, like
VLA's and designated initializers. But since most of the people
who prefer C over C++ also reject C99, I'll not go into those.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Juha Nieminen

10/25/2008 9:38:00 AM

0

James Kanze wrote:
>> 1) Anything you can do in C, you can do in C++.
>
> That's not true:

I didn't say "any C program is a valid C++ program". What I said was
"anything you can do in C, you can do in C++".

Sure, there are a few cases where the type system of C++ is slightly
stricter than C's (although I'm a bit surprised this is still the case
with C99), but I wouldn't say that's a very radical difference.

Of if I put that in other terms: If someone considered C++ to be worse
exclusively because you have to declare functions before you use them,
that would be a rather stupid and trivial argument. When C hackers bash
C++, they are not talking about function declarations and void pointers,
they are talking about what C++ *adds* to the language that C doesn't
have (such as templates).

SG

10/25/2008 10:29:00 AM

0

On 24 Okt., 21:44, "Chris M. Thomasson" <n...@spam.invalid> wrote:
> You can get "fairly clean" abstract interfaces in C; something as simple as;
> quick code scribbling - may have typo:
>
> [... C++ abstract class and virtual function emulation in plain C ...]
>
> There... simple!

Well, that was a really simple case, wasn't it? Try inheriting from
more than one abstract class. :-) My point is: You can code "OO style"
in plain C. But it's gonna be verbose and error-prone. I have to admit
I didn't try any of the available frameworks for "OO-emulation in
plain C" (like GObject). Spending time learning these frameworks
instead of learning C++ doesn't seem like a good choice to me since C+
+ has other neat things to offer:
- RAII (one of the biggest selling points IMHO)
- support for generic programming (via templates, also big selling
point)

Cheers,
SG

Ian Collins

10/25/2008 10:34:00 AM

0

Juha Nieminen wrote:
>
> Of if I put that in other terms: If someone considered C++ to be worse
> exclusively because you have to declare functions before you use them,
> that would be a rather stupid and trivial argument. When C hackers bash
> C++, they are not talking about function declarations and void pointers,
> they are talking about what C++ *adds* to the language that C doesn't
> have (such as templates).

They tend to work them selves up into a lather about the added
complexity of C++ while refusing to acknowledge the complexity is optional.

--
Ian Collins

Chris M. Thomasson

10/25/2008 3:18:00 PM

0


"SG" <s.gesemann@gmail.com> wrote in message
news:f523aee3-ff9c-4f11-91ac-e476cfe6077a@i76g2000hsf.googlegroups.com...
> On 24 Okt., 21:44, "Chris M. Thomasson" <n...@spam.invalid> wrote:
>> You can get "fairly clean" abstract interfaces in C; something as simple
>> as;
>> quick code scribbling - may have typo:
>>
>> [... C++ abstract class and virtual function emulation in plain C ...]
>>
>> There... simple!
>
> Well, that was a really simple case, wasn't it?

Indeed. Although, I personally like to use the minimalist technique I
described for plug-in frameworks.




> Try inheriting from more than one abstract class. :-)

Ouch! :^(




> My point is: You can code "OO style"
> in plain C. But it's gonna be verbose and error-prone.

Fair enough.




> I have to admit
> I didn't try any of the available frameworks for "OO-emulation in
> plain C" (like GObject). Spending time learning these frameworks
> instead of learning C++ doesn't seem like a good choice to me since C+
> + has other neat things to offer:
> - RAII (one of the biggest selling points IMHO)
> - support for generic programming (via templates, also big selling
> point)

Agreed.