Is c++ only better c ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pawel_Iks

    Is c++ only better c ?

    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?
  • Maxim Yegorushkin

    #2
    Re: Is c++ only better c ?

    On Oct 24, 10:27 am, Pawel_Iks <pawel.labed... @gmail.comwrote :
    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

    Comment

    • James Kanze

      #3
      Re: Is c++ only better c ?

      On Oct 24, 11:55 am, Maxim Yegorushkin <maxim.yegorush ...@gmail.com>
      wrote:
      On Oct 24, 10:27 am, Pawel_Iks <pawel.labed... @gmail.comwrote :
      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:james.kan ze@gmail.com
      Conseils en informatique orientée objet/
      Beratung in objektorientier ter Datenverarbeitu ng
      9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

      Comment

      • osmium

        #4
        Re: Is c++ only better c ?

        "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..




        Comment

        • Chris M. Thomasson

          #5
          Re: Is c++ only better c ?


          "James Kanze" <james.kanze@gm ail.comwrote in message
          news:ded8588f-baa2-4229-a17e-b658a95105fc@34 g2000hsh.google groups.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.comwrote :
          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_Destr oy) (void*);
          void (*IShape_Draw) (void*);
          /* ect... */
          };

          struct IShape {
          struct IShape_VTable* VTable;
          };

          #define IObject_Destroy (Self) ( \
          (Self)->VTable->IObject_Destro y((Self)) \
          )

          #define IShape_Draw(sel f) ( \
          (Self)->VTable->IShape_Draw((S elf)) \
          )




          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_D raw(void*);


          static struct IShape_VTable Circle_VTable = {
          Circle_IObject_ Destroy,
          Circle_IShape_D raw
          };


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


          struct IShape*
          Circle_Create(
          /* ... */
          ) {
          struct Circle* Self = malloc(*Self);
          if (Self) {
          Self->IShape.VTabl e = &Circle_VTab le;
          return &Self->IShape;
          }
          return NULL;
          }


          void
          Circle_IObject_ Destroy(
          void* IObject
          ) {
          free(IObject);
          }


          void
          Circle_IShape_D raw(
          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(Sha pe);
          IObject_Destroy (Shape);
          return 0;
          }




          There... simple!

          ;^D

          Comment

          • Juha Nieminen

            #6
            Re: Is c++ only better c ?

            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).

            Comment

            • James Kanze

              #7
              Re: Is c++ only better c ?

              On Oct 24, 11:43 pm, Juha Nieminen <nos...@thanks. invalidwrote:
              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.kan ze@gmail.com
              Conseils en informatique orientée objet/
              Beratung in objektorientier ter Datenverarbeitu ng
              9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

              Comment

              • Juha Nieminen

                #8
                Re: Is c++ only better c ?

                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).

                Comment

                • SG

                  #9
                  Re: Is c++ only better c ?

                  On 24 Okt., 21:44, "Chris M. Thomasson" <n...@spam.inva lidwrote:
                  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

                  Comment

                  • Ian Collins

                    #10
                    Re: Is c++ only better c ?

                    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

                    Comment

                    • Chris M. Thomasson

                      #11
                      Re: Is c++ only better c ?


                      "SG" <s.gesemann@gma il.comwrote in message
                      news:f523aee3-ff9c-4f11-91ac-e476cfe6077a@i7 6g2000hsf.googl egroups.com...
                      On 24 Okt., 21:44, "Chris M. Thomasson" <n...@spam.inva lidwrote:
                      >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.

                      Comment

                      • Jeff Schwab

                        #12
                        Re: Is c++ only better c ?

                        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?
                        Do you write code in either of those languages?

                        Comment

                        • Juha Nieminen

                          #13
                          Re: Is c++ only better c ?

                          Ian Collins wrote:
                          They tend to work them selves up into a lather about the added
                          complexity of C++ while refusing to acknowledge the complexity is optional.
                          What bothers me the most with their argument about "added complexity"
                          is that it feels like they have actually never even tried this "added
                          complexity" they are talking about.

                          The basic mistake in thinking is that "more features" equals to "more
                          complexity", which equals to "the language is harder to use and
                          understand". They emphasize that C is good because it's so simple.

                          There is no such equality. More features don't automatically make the
                          language more complex. In fact, it's often the exact opposite: More
                          features can make using the language *simpler*, not more complicated.

                          Comment

                          • Juha Nieminen

                            #14
                            Re: Is c++ only better c ?

                            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?
                            I think that this is just an argument about semantics. If you say "C++
                            is something more than just a better C" that sentence has a positive
                            exalting tone to it, but if you say "C++ is nothing more than a better
                            C" that sentence has a belittling and unappreciating tone. In the end,
                            both sentences are saying the exact same thing. There's just a
                            difference in attitude.

                            Comment

                            • s0suk3@gmail.com

                              #15
                              Re: Is c++ only better c ?

                              On Oct 24, 2:44 pm, "Chris M. Thomasson" <no@spam.invali dwrote:
                              "James Kanze" <james.kanze@gm ail.comwrote in message
                              >
                              news:ded8588f-baa2-4229-a17e-b658a95105fc@34 g2000hsh.google groups.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.comwrote :
                              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_Destr oy) (void*);
                                void (*IShape_Draw) (void*);
                                /* ect... */
                              >
                              };
                              >
                              struct IShape {
                                struct IShape_VTable* VTable;
                              >
                              };
                              >
                              #define IObject_Destroy (Self) ( \
                                (Self)->VTable->IObject_Destro y((Self)) \
                              )
                              >
                              #define IShape_Draw(sel f) ( \
                                (Self)->VTable->IShape_Draw((S elf)) \
                              )
                              >
                              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_D raw(void*);
                              >
                              static struct IShape_VTable Circle_VTable = {
                                Circle_IObject_ Destroy,
                                Circle_IShape_D raw
                              >
                              };
                              >
                              struct Circle {
                                struct IShape IShape;
                                /* ... */
                              >
                              };
                              >
                              struct IShape*
                              Circle_Create(
                               /* ... */
                              ) {
                                struct Circle* Self = malloc(*Self);
                                if (Self) {
                                  Self->IShape.VTabl e = &Circle_VTab le;
                                  return &Self->IShape;
                                }
                                return NULL;
                              >
                              }
                              >
                              void
                              Circle_IObject_ Destroy(
                               void* IObject
                              ) {
                                free(IObject);
                              >
                              }
                              >
                              void
                              Circle_IShape_D raw(
                               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(Sha pe);
                                IObject_Destroy (Shape);
                                return 0;
                              >
                              }
                              >
                              There... simple!
                              >
                              ;^D
                              I used to code C in ways very similar to that, but it's a total
                              nightmare. It's not what C was designed for, and it's not the way to
                              code it (incidentally, it's the only *productive* way to code it!).

                              It's basically a faking of basic OO concepts such as an abstract type
                              with operations bundled to it, and it can be a clean way to code basic
                              applications. At a large scale, however, the lack of language support
                              for these programming techniques leads to a great deal of verbosity
                              and boilerplate code, almost to the point where the disadvantages
                              outweigh the advantages (it even increases the risk of memory leaks!).

                              C just isn't a good scaling language.

                              Sebastian

                              Comment

                              Working...