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. | | | | re: OOP campyhapper@yahoo.com said: Quote:
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 | | | | re: OOP
On Jun 30, 12:35*pm, Richard Heathfield <r...@see.sig.invalidwrote: Quote:
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 incomprehensible than if I say I'm
a C programmer. | | | | re: OOP
>>>>"ch" == campyhapper <campyhapper@yahoo.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@chromatico.net | | | | re: OOP campyhapper@yahoo.com writes: Quote:
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_Keith) 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" | | | | re: OOP
pete wrote: Quote: campyhapper@yahoo.com wrote: Quote:
>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*sizeof(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.vw | tr i-za-h a-z> | | | | re: OOP campyhapper@yahoo.com said:
<snip> Quote:
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 incomprehensible 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 | | | | re: OOP
Tor Rustad wrote: Quote:
pete wrote: Quote:
> campyhapper@yahoo.com wrote: Quote:
>>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*sizeof(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: http://www.mindspring.com/~pfilandr/C/e_driver/
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 | | | | re: OOP campyhapper@yahoo.com wrote: Quote:
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. :-) | | | | re: OOP
In comp.lang.c, campyhapper@yahoo.com wrote: Quote:
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 straightforwardness of C. If you are
interested, you can take a look at version 3.3 at http://www.softwarepreservation.org/...us_plus/cfront
--
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. ------ | | | | re: OOP
On 2008-06-30 17:27:05 +0100, campyhapper@yahoo.com said: Quote:
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 | | | | re: OOP
On Jun 30, 9:27*am, campyhap...@yahoo.com wrote: Quote:
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++. | | | | re: OOP
On Jun 30, 2:18*pm, Lew Pitcher <lpitc...@teksavvy.comwrote: Quote:
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. | | | | re: OOP campyhapper@yahoo.com wrote: Quote:
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. | | | | re: OOP campyhapper@yahoo.com wrote: Quote:
>... 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++: http://www.caravan.net/ec2plus/
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 ] | | | | re: OOP
"Sjouke Burry" <burrynulnulfour@ppllaanneett.nnlllwrote in message Quote:
Why not just use the features you want and ignore the
ones you dont like??
The language will work just as well.
>
There are some snags. For instance if we write a "constructor" in C the
natural thing to do is to return a null pointer if the function fails. There
is no way to do this in C++. So the solution is to throw an exception. Which
means that if you use constructors that either validate parameters or
acquire resoruces, exceptions are mandatory.
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm | | | | re: OOP campyhapper@yahoo.com wrote: Quote:
And if I'm going to turn back the clock, I
might as well go with Objective C.
That is a fairly ignorant statement about Objective-C. There is
nothing "out-of-date" about it, or perhaps you've never heard of Mac OS X
(they just came out with a new point release)?
And despite your dismissal of it, ObjC fulfills your description of the
language you want precisely: Quote:
and disallows things like templates, multiple inheritance and the like?
Check. No templates and MI is explicitly disallowed. | | | | re: OOP
On Jun 30, 10:14*pm, "Sean G. McLaughlin" <non...@domain.invalid>
wrote: Quote:
And despite your dismissal of it, ObjC fulfills your description of the
language you want precisely:
> Quote:
and disallows things like templates, multiple inheritance and the like?
>
Check. *No templates and MI is explicitly disallowed.
I was being sarcastic. I didn't mean to disrespect your beloved
language and hurt your tender feelings. I am quite ashamed of my
heartless conduct in ever so slightly diminishing ObjC's shimmering
and glistening vitality, which is like a newly formed fine ocean
spray, even while Apple's ObjC libraries are largely the intellectual
property of Apple(TM) Computer, (R) Inc., destroyer of ThinkSecret and
eviscerater of select iPhone-clone retailers, and are therefore off-
limits like a dank moss-covered basement reeking of urine. | | | | re: OOP
On Jun 30, 9:27 pm, campyhap...@yahoo.com wrote: Quote:
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 do you want a new lang. if what you want is really a subset of C+
+? May be implementing object oriented concepts in C itself will solve
your purpose. (As pete demonstrated) | | | | re: OOP
On Jul 2, 4:37*am, rahul <rahulsin...@gmail.comwrote: Quote:
>
Why do you want a new lang. if what you want is really a subset of C+
+? May be implementing object oriented concepts in C itself will solve
your purpose. (As pete demonstrated)
That's what I usually do, and I've had success with that,
although it's like reinventing the wheel for every project.
There may come a day when I will just release my
"classes" for general consumption and see if they
gain any traction.
Or, I will just switch to Objective C. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,295 network members.
|