Newbie: The C / C++ Issue

Louis LeBlanc freebsd at
Wed Nov 12 19:24:26 PST 2003

On 11/12/03 09:36 PM, Lucas Holt sat at the `puter and typed:
> On Nov 12, 2003, at 8:37 PM, Marty Leisner wrote:
> >
> >
> > BTW -- I've been doing "object oriented" stuff in C for years --
> > its harder, but its doable.  You have a much simpler language to
> > deal with.
> >
> > First learn how to write good programs in C.  Then see if C++ buys
> > you anything extra.  If it doesn't, you don't need C++.  But I've
> > seen far too much C++ that's just obscure C.
> >
> > Just my experience and opinion.
> >
> > marty
> Am I missing something here?  When does C have OO capability?
> Structs don't count.  What about inheritance and polymorphism?

That's in the implementation AND application.  Just because you CAN
access part of a lowly struct, doesn't mean you have to.  It's object
oriented if you OBSERVE the restricted accesses defined by OO.
Whether or not they're there is completely irrelevant.  Of course C
has OO capability, it just doesn't have its restrictions :)

> To me a struct is like a VCR with no record button.  You can view
> the content, but you can't manipulate it with the struct.  If i want
> to do something to destroy the tape, I must apply a magnet from an
> outside source (much like a plain old function).  And classes
> provide security, much like the tab on the front of the tape.  The
> data is private if the tab is puched out.  (ok thats a bad analogy)

Seems to me it's more like a VCR tape with the tab taped over.

If you declare a struct, and then implement a specific set of routines
to manipulate it, and only use those routines, except for those 'data
members' that would otherwise be public anyway, that's essentially
your class.  You're doing without all the type and access restrictions
IMPOSED by C++, but that doesn't mean you can't OBSERVE those
restrictions.  This way, when saving cpu time is critical, you can
bend those rules.  With C++, you're stuck on the long road.

> If C had OO features, then why do we have C++ and Objective C?

Because some people like C++ better.

> I would agree that you can write programs that do the same thing in
> all three languages above, but I don't think that OO is a waste of
> time.  OO promotes code reuse.  That is the whole point.

No one ever claimed OO was a waste of time that I noticed.  But I
don't see code reuse with C++ any more than with C.  I'm a real big
fan of code reuse, and I have reused more C code than I can remember.
Problem is that when C++ code gets reused, it's usually a template
class, in which case, you'd probably be better off with C anyway.
When I reuse C code, it's a copied data structure and a set of
routines that will apply to the task at hand, not a third generation
inherited template class with half it's methods redefined.

> Using C++ implies a state of mind.  You can write code like in C,
> but it defeats the purpose of using an OO language.

Not sure what you mean by this, but if using C++ is a state of mind,
why can't that state of mind affect the way C code is written?  And it
doesn't defeat the purpose if you misbehave regularly and NEED the
unbreakable restrictions.

Just another $0.02

Louis LeBlanc               leblanc at
Fully Funded Hobbyist, KeySlapper Extrordinaire :)                     Ô¿Ô¬

You're a good example of why some animals eat their young.
    -- Jim Samuels to a heckler

More information about the freebsd-questions mailing list