Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is c++ only better c ?

Reply
Thread Tools

Is c++ only better c ?

 
 
Pawel_Iks
Guest
Posts: n/a
 
      10-24-2008
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?
 
Reply With Quote
 
 
 
 
Maxim Yegorushkin
Guest
Posts: n/a
 
      10-24-2008
On Oct 24, 10:27*am, Pawel_Iks <(E-Mail Removed)> 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.org/?p=532

--
Max
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      10-24-2008
On Oct 24, 11:55 am, Maxim Yegorushkin <(E-Mail Removed)>
wrote:
> On Oct 24, 10:27 am, Pawel_Iks <(E-Mail Removed)> 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.org/?p=532


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:(E-Mail Removed)
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
 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      10-24-2008
"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/bs_faq.html


 
Reply With Quote
 
Chris M. Thomasson
Guest
Posts: n/a
 
      10-24-2008

"James Kanze" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Oct 24, 11:55 am, Maxim Yegorushkin <(E-Mail Removed)>
wrote:
> On Oct 24, 10:27 am, Pawel_Iks <(E-Mail Removed)> 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.org/?p=532


> 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

 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      10-24-2008
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).
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      10-25-2008
On Oct 24, 11:43*pm, Juha Nieminen <(E-Mail Removed)> 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:(E-Mail Removed)
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
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      10-25-2008
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).
 
Reply With Quote
 
SG
Guest
Posts: n/a
 
      10-25-2008
On 24 Okt., 21:44, "Chris M. Thomasson" <(E-Mail Removed)> 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
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      10-25-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GL2 better than the XLs? Consumer grade HDs better than pro-sumer Mini DVs? dh@. DVD Video 1 08-28-2008 07:20 PM
The SCO case gets better and better.... thingy NZ Computing 2 12-10-2006 11:33 AM
Is splint really better than lint? Is there a better tool than splint? Peter Bencsik C Programming 2 09-21-2006 10:02 PM
Build a Better Blair (like Build a Better Bush, only better) Kenny Computer Support 0 05-06-2005 04:50 AM
Why doesn't the better camera have a better dpi? Tony Carlisle Digital Photography 6 10-04-2003 10:40 AM



Advertisments