OOP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • campyhapper@yahoo.com

    OOP

    Hi folks,

    I tend to prefer C, and of course I know that structs
    can be used in C to achieve something like
    an object-oriented design. And I prefer C in part
    because C++ has, I think, grown into a bit of a
    monster wherein readability is sacrificed.
    But I wonder, has anyone ever tried to create a
    sort of lite version of C++, a C+ if you will, that adds
    to C just a few key features and disallows things
    like templates, multiple inheritance and the like?

    Thanks.
  • Richard Heathfield

    #2
    Re: OOP

    campyhapper@yah oo.com said:
    Hi folks,
    >
    I tend to prefer C, and of course I know that structs
    can be used in C to achieve something like
    an object-oriented design. And I prefer C in part
    because C++ has, I think, grown into a bit of a
    monster wherein readability is sacrificed.
    But I wonder, has anyone ever tried to create a
    sort of lite version of C++, a C+ if you will, that adds
    to C just a few key features and disallows things
    like templates, multiple inheritance and the like?
    Yes. It never works very well. If that's what you want, just use C++ and
    discipline yourself not to use the features that you think hamper
    readability. (That is what I already do in C. The fact that goto, say, is
    available does not mean that I am required to use it.)

    --
    Richard Heathfield <http://www.cpax.org.uk >
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999

    Comment

    • campyhapper@yahoo.com

      #3
      Re: OOP

      On Jun 30, 12:35 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
      Yes. It never works very well. If that's what you want, just use C++ and
      discipline yourself not to use the features that you think hamper
      readability. (That is what I already do in C. The fact that goto, say, is
      available does not mean that I am required to use it.)
      You have a point. And I know that nothing I do or say
      will stop others from using C++'s problematic features
      or even its good features in bad ways.

      But an analogy might be that C is like a car,
      C++ is like a motorcycle. Accidents happen
      more readily with motorcycles and with C++.
      And although I'm a careful driver of all vehicles,
      and a careful coder, chances are higher that,
      if I say to an employer "I'm a C++ programmer"
      they will stick me with someone else's C++ code
      that is incomprehensibl e than if I say I'm
      a C programmer.

      Comment

      • Charlton Wilbur

        #4
        Re: OOP

        >>>>"ch" == campyhapper <campyhapper@ya hoo.comwrites:

        chBut I wonder, has anyone ever tried to create a sort of lite
        chversion of C++, a C+ if you will, that adds to C just a few key
        chfeatures and disallows things like templates, multiple
        chinheritance and the like?

        C++ has a philosophy of not making you pay for language features you
        don't use. Use C++, but don't use the features you don't like.

        Charlton


        --
        Charlton Wilbur
        cwilbur@chromat ico.net

        Comment

        • Keith Thompson

          #5
          Re: OOP

          campyhapper@yah oo.com writes:
          I tend to prefer C, and of course I know that structs
          can be used in C to achieve something like
          an object-oriented design. And I prefer C in part
          because C++ has, I think, grown into a bit of a
          monster wherein readability is sacrificed.
          But I wonder, has anyone ever tried to create a
          sort of lite version of C++, a C+ if you will, that adds
          to C just a few key features and disallows things
          like templates, multiple inheritance and the like?
          There have been a number of such attempts. As far as I know, no two
          of them agree on which features are vital and which should be
          discarded.

          --
          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
          Nokia
          "We must do something. This is something. Therefore, we must do this."
          -- Antony Jay and Jonathan Lynn, "Yes Minister"

          Comment

          • Tor Rustad

            #6
            Re: OOP

            pete wrote:
            campyhapper@yah oo.com wrote:
            >Hi folks,
            >>
            >I tend to prefer C, and of course I know that structs
            >can be used in C to achieve something like
            >an object-oriented design. And I prefer C in part
            >because C++ has, I think, grown into a bit of a
            >monster wherein readability is sacrificed.
            >But I wonder, has anyone ever tried to create a
            >sort of lite version of C++, a C+ if you will, that adds
            >to C just a few key features and disallows things
            >like templates, multiple inheritance and the like?
            >
            I got the e_type interface for sorting functions from Dann Corbit.
            It's a step in the direction towards templates. I like it.
            All you have to do is
            #define E_TYPE /* array element type */
            and
            #define GT(A, B) /* a "Greater Than" macro */
            and you can sort a one dimensional array of any type.

            Interesting, this reminds me of the ADT trick used by Sedgewick, in his
            "Algorithms in C" books, where an algorithm implementation could look
            like this:


            #include <stdlib.h>
            #include "Item.h"
            #include "STACK.h"
            static Item *s;
            static int N;
            void STACKinit(int maxN)
            { s = malloc(maxN*siz eof(Item)); N = 0; }
            int STACKempty()
            { return N == 0; }
            void STACKpush(Item item)
            { s[N++] = item; }
            Item STACKpop()
            { return s[--N]; }


            while the user write an <Item.hand call the generic algorithms like this:

            #include <stdio.h>
            #include <string.h>
            #include "Item.h"
            #include "STACK.h"
            main(int argc, char *argv[])
            { char *a = argv[1]; int i, N = strlen(a);
            STACKinit(N);
            for (i = 0; i < N; i++)
            {
            if (a[i] == ')')
            printf("%c ", STACKpop());
            if ((a[i] == '+') || (a[i] == '*'))
            STACKpush(a[i]);
            if ((a[i] >= '0') && (a[i] <= '9'))
            printf("%c ", a[i]);
            }
            printf("\n");
            }


            --
            Tor <echo bwzcab@wvtqvm.v w | tr i-za-h a-z>

            Comment

            • Richard Heathfield

              #7
              Re: OOP

              campyhapper@yah oo.com said:

              <snip>
              And although I'm [...] a careful coder, chances are
              higher that, if I say to an employer "I'm a C++
              programmer" they will stick me with someone else's
              C++ code that is incomprehensibl e than if I say I'm
              a C programmer.
              And if you say you're a "C with some extra bits added that don't quite add
              up to C++" programmer, they are likely to conclude that you can't hack C
              without the extra bits, and can't hack C++ with the non-extra bits.

              In other words, if you specialise in what we might call C++-- (erroneous
              construct notwithstanding ), you are likely to find that your job choice is
              more restricted than if you specialise in either C or C++.

              --
              Richard Heathfield <http://www.cpax.org.uk >
              Email: -http://www. +rjh@
              Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
              "Usenet is a strange place" - dmr 29 July 1999

              Comment

              • pete

                #8
                Re: OOP

                Tor Rustad wrote:
                pete wrote:
                >campyhapper@yah oo.com wrote:
                >>Hi folks,
                >>>
                >>I tend to prefer C, and of course I know that structs
                >>can be used in C to achieve something like
                >>an object-oriented design. And I prefer C in part
                >>because C++ has, I think, grown into a bit of a
                >>monster wherein readability is sacrificed.
                >>But I wonder, has anyone ever tried to create a
                >>sort of lite version of C++, a C+ if you will, that adds
                >>to C just a few key features and disallows things
                >>like templates, multiple inheritance and the like?
                >>
                >I got the e_type interface for sorting functions from Dann Corbit.
                >It's a step in the direction towards templates. I like it.
                >All you have to do is
                >#define E_TYPE /* array element type */
                >and
                >#define GT(A, B) /* a "Greater Than" macro */
                >and you can sort a one dimensional array of any type.
                >
                >
                Interesting, this reminds me of the ADT trick used by Sedgewick, in his
                "Algorithms in C" books, where an algorithm implementation could look
                like this:
                >
                >
                #include <stdlib.h>
                #include "Item.h"
                #include "STACK.h"
                static Item *s;
                static int N;
                void STACKinit(int maxN)
                { s = malloc(maxN*siz eof(Item)); N = 0; }
                int STACKempty()
                { return N == 0; }
                void STACKpush(Item item)
                { s[N++] = item; }
                Item STACKpop()
                { return s[--N]; }
                >
                >
                while the user write an <Item.hand call the generic algorithms like this:
                >
                #include <stdio.h>
                #include <string.h>
                #include "Item.h"
                #include "STACK.h"
                main(int argc, char *argv[])
                { char *a = argv[1]; int i, N = strlen(a);
                STACKinit(N);
                for (i = 0; i < N; i++)
                {
                if (a[i] == ')')
                printf("%c ", STACKpop());
                if ((a[i] == '+') || (a[i] == '*'))
                STACKpush(a[i]);
                if ((a[i] >= '0') && (a[i] <= '9'))
                printf("%c ", a[i]);
                }
                printf("\n");
                }
                I have a six file program for timing sorting functions here:


                The element type and GT macros are defined in e_driver.h,
                and all the other *.h files and e_driver.c, include it.

                It's set up so that simply by flipping a macro to either 1 or 0,
                the program will either sort arrays of unsigned long
                or arrays of structs,
                which contain an array of 50 char and a type double data member.

                --
                pete

                Comment

                • santosh

                  #9
                  Re: OOP

                  campyhapper@yah oo.com wrote:
                  Hi folks,
                  >
                  I tend to prefer C, and of course I know that structs
                  can be used in C to achieve something like
                  an object-oriented design. And I prefer C in part
                  because C++ has, I think, grown into a bit of a
                  monster wherein readability is sacrificed.
                  But I wonder, has anyone ever tried to create a
                  sort of lite version of C++, a C+ if you will, that adds
                  to C just a few key features and disallows things
                  like templates, multiple inheritance and the like?
                  Here's your cue Jacob. :-)

                  Comment

                  • Lew Pitcher

                    #10
                    Re: OOP

                    In comp.lang.c, campyhapper@yah oo.com wrote:
                    Hi folks,
                    >
                    I tend to prefer C, and of course I know that structs
                    can be used in C to achieve something like
                    an object-oriented design. And I prefer C in part
                    because C++ has, I think, grown into a bit of a
                    monster wherein readability is sacrificed.
                    But I wonder, has anyone ever tried to create a
                    sort of lite version of C++, a C+ if you will, that adds
                    to C just a few key features and disallows things
                    like templates, multiple inheritance and the like?
                    The original cfront "C with Classes" C++ translator was last updated in
                    January 2007. Perhaps cfront would provide you with the C++ features you
                    wish while still maintaining the straightforward ness of C. If you are
                    interested, you can take a look at version 3.3 at


                    --
                    Lew Pitcher

                    Master Codewright & JOAT-in-training | Registered Linux User #112576
                    http://pitcher.digitalfreehold.ca/ | GPG public key available by request
                    ---------- Slackware - Because I know what I'm doing. ------


                    Comment

                    • Cromulent

                      #11
                      Re: OOP

                      On 2008-06-30 17:27:05 +0100, campyhapper@yah oo.com said:
                      Hi folks,
                      >
                      I tend to prefer C, and of course I know that structs
                      can be used in C to achieve something like
                      an object-oriented design. And I prefer C in part
                      because C++ has, I think, grown into a bit of a
                      monster wherein readability is sacrificed.
                      But I wonder, has anyone ever tried to create a
                      sort of lite version of C++, a C+ if you will, that adds
                      to C just a few key features and disallows things
                      like templates, multiple inheritance and the like?
                      >
                      Thanks.
                      There is a book called Object Orientated Programming in ANSI C. You may
                      want to check it out, not sure how good it is as I have not had a
                      chance to read it (on my list) but if you are interested it is out
                      there.
                      --
                      "I disapprove of what you say, but I'll defend to the death your right
                      to say it." - Voltaire

                      Comment

                      • Kaz Kylheku

                        #12
                        Re: OOP

                        On Jun 30, 9:27 am, campyhap...@yah oo.com wrote:
                        But I wonder, has anyone ever tried to create a
                        sort of lite version of C++, a C+ if you will, that adds
                        to C just a few key features and disallows things
                        like templates, multiple inheritance and the like?
                        Yes. Bjarne Stroustrup did this (around 1981, IIRC) and called it ``C
                        with classes''. It translated a C-like language with OOP features into
                        C. This evolved into C++.

                        Comment

                        • campyhapper@yahoo.com

                          #13
                          Re: OOP

                          On Jun 30, 2:18 pm, Lew Pitcher <lpitc...@teksa vvy.comwrote:
                          The original cfront "C with Classes" C++ translator was last updated in
                          January 2007.
                          Right but who uses it? And if I'm going to turn back the clock, I
                          might as well go with Objective C.

                          Comment

                          • Sjouke Burry

                            #14
                            Re: OOP

                            campyhapper@yah oo.com wrote:
                            Hi folks,
                            >
                            I tend to prefer C, and of course I know that structs
                            can be used in C to achieve something like
                            an object-oriented design. And I prefer C in part
                            because C++ has, I think, grown into a bit of a
                            monster wherein readability is sacrificed.
                            But I wonder, has anyone ever tried to create a
                            sort of lite version of C++, a C+ if you will, that adds
                            to C just a few key features and disallows things
                            like templates, multiple inheritance and the like?
                            >
                            Thanks.
                            Why not just use the features you want and ignore the
                            ones you dont like??
                            The language will work just as well.

                            Comment

                            • Roberto Waltman

                              #15
                              Re: OOP

                              campyhapper@yah oo.com wrote:
                              >... has anyone ever tried to create a
                              >sort of lite version of C++, a C+ if you will, that adds
                              >to C just a few key features and disallows things
                              >like templates, multiple inheritance and the like?
                              See Embedded C++:


                              As others pointed out already, it is not better than restricting
                              yourself to a subset of the language.
                              (Unless you are implementing a compiler for that subset.)
                              --
                              Roberto Waltman

                              [ Please reply to the group,
                              return address is invalid ]

                              Comment

                              Working...