I disagree with nearly all of what you have said when you say “in
c++” or the like. I would urge you to take your argument one thing at
a time to a c++ coder community and see what comes out. Some things
are obscure because people don’t like to do it or teach it can be
done that way. ---- @Zoltan_Kocsi wrote:
Um, which bit do you disagree with? That Smalltalk and Obj-C are object
oriented, or that Obj-C is much simpler to learn than C++ or that with
C++ you have a lot less knowledge of exactly what functions are called
and when than in C or that in C you can write opaque data types while a
C++ class (by definition) can not hide the actual content of the class?
It wasn’t a criticism of C++ as such (although, I admit, I do not like
it but that’s irrelevant, really), it was a statement that compile-time
type checking is not a necessary feature in an object oriented language.
In addition, especially in embedded systems you really want to know
what’s being executed and when. In C that’s straightforward, in C++,
when the compiler generates a lot of code, you can’t be that sure.
As per the opaque data types, it is self-evident, I think.
Regards,
ZoltanOn Thu, 26 Feb 2009 20:16:58 -0500 wrote:
=============
I’m sorry to disagree with you. The difference is between
"compile-time typechecking" and “run-time typechecking”. The former
can only be done in a OO language featuring function-overloading
and virtual functions.
I thought that Objective-C was an object oriented language. Heavily
relying on Smalltalk, the facther of the OO languages. Both of them
are based on run-type type checking, so much so that in Smalltalk
even an integer is an object. C++ might be more efficient than
Objective-C (although I am not absolutely sure), but Objective-C is
as object oriented as they get. It doesn’t have virtual functions
(although it has protocols and a few other bits that provide pretty
much the same functionality) but it can deal with remote objects,
for example. You can ask the compiler to do compile time type checks
if efficiency is a concern at a given place of the program, but
run-time resolution is the core feature.
So, run-time typechecking is just as object oriented as compile-time.
In fact, even more. In Objective-C you can send a message (invoke a
member function) to an object that you’ve never heard about. As long
as it implements the method, it will respond to it. Most importantly,
you can ask every object what they are, if they implement a method or
not and so on. Added bonus is that Objective-C adds maybe 10 keywords
to normal C, with absolutely minimum extra syntax. Any ANSI C program
is also a valid Objective-C program (unlike C -> C++) and Objective-C
can be fully described to a C programmer on about 20 pages. Now try
that with C++…
And about that translating to C by the first C++ compilers …
During the translation a lot of extra variables and macro’s where
inserted, e.g. in order to generate unique function names for each
method and function. It is not completely impossible to do this by
hand of course, but why would you?
Because then you know what’s there exactly. Some people like to know
what’s going on. By the way, you do not need to have unique function
names. Consider write() that works quite fine on the serial port
object, any file object, any raw block device object, any pipe
object, a network connection object and pretty much on any object
that can receive user data. It is not that bad to use write( fd … )
instead of fd.write(…).
In C to a degree you can be more object-oriented than in C++. You can
have opaque data types that really hide the implementation details
from the user while in C++ you must expose your class structure even
if the user will never need to know its internal details or even its
size.
Zoltan
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org