473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.
Jun 30 '08 #1
19 1414
ca*********@yahoo.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
Jun 30 '08 #2
On Jun 30, 12:35*pm, Richard Heathfield <r...@see.sig.invalidwrote:
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.

Jun 30 '08 #3
>>>>"ch" == campyhapper <ca*********@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
cw*****@chromatico.net
Jun 30 '08 #4
ca*********@yahoo.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_Keith) ks***@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"
Jun 30 '08 #5
pete wrote:
ca*********@yahoo.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*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 bw****@wvtqvm.vw | tr i-za-h a-z>
Jun 30 '08 #6
ca*********@yahoo.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 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
Jun 30 '08 #7
Tor Rustad wrote:
pete wrote:
>ca*********@yahoo.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*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
Jun 30 '08 #8
ca*********@yahoo.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. :-)

Jun 30 '08 #9
In comp.lang.c, ca*********@yahoo.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 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. ------
Jun 30 '08 #10
On 2008-06-30 17:27:05 +0100, ca*********@yahoo.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

Jun 30 '08 #11
On Jun 30, 9:27*am, campyhap...@yahoo.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++.
Jun 30 '08 #12
On Jun 30, 2:18*pm, Lew Pitcher <lpitc...@teksavvy.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.
Jun 30 '08 #13
ca*********@yahoo.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.
Jun 30 '08 #14
ca*********@yahoo.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++:
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 ]
Jun 30 '08 #15

"Sjouke Burry" <bu*************@ppllaanneett.nnlllwrote in message
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

Jun 30 '08 #16
ca*********@yahoo.com wrote:
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:
and disallows things like templates, multiple inheritance and the like?
Check. No templates and MI is explicitly disallowed.
Jul 1 '08 #17
On Jun 30, 10:14*pm, "Sean G. McLaughlin" <non...@domain.invalid>
wrote:
And despite your dismissal of it, ObjC fulfills your description of the
language you want precisely:
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.

Jul 1 '08 #18
On Jun 30, 9:27 pm, campyhap...@yahoo.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 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)
Jul 2 '08 #19
On Jul 2, 4:37*am, rahul <rahulsin...@gmail.comwrote:
>
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.

Jul 2 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.