Newbie: The C / C++ Issue
abowhill at blarg.net
Thu Nov 13 11:02:28 PST 2003
> 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 :)
The idea that C can be used to do object-oriented programming is
a myth. The C language is not object-oriented or even object-based.
The big reason C++ is object-oriented is due to dynamic binding.
Check out the C++ FAQ lite:
>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.
You can drive your car to an open plain in the desert, and
operate the vehicle as if you were in the city, observing imaginary
stop lights, lanes and traffic. But why pretend?
The systematic constraints in C++ exist to organize code,
protect your work. They are there for the same basic reasons that
local variables exist in C.
>> 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.
There are so many different ways to re-use code. Even cutting and
pasting, which is essentially what the STL does. (correct me if
I am wrong)
If you are going to re-use code, at least be organized, make
a good interface, and don't re-invent the wheel unless you
have to. C, C++, whatever.
>> 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
Components in the real-world problem map directly to objects in the
program. C++ was designed to be used this way. C was not.
More information about the freebsd-questions