[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: C++ templates (was: Re: To all german speaking 'steppers: article in
From: |
Pascal Bourguignon |
Subject: |
RE: C++ templates (was: Re: To all german speaking 'steppers: article in german C'tmagazine <VirusChecked>) |
Date: |
Fri, 30 May 2003 15:07:19 +0200 |
Tima Vaisburd writes:
>
> There is another, less techical consideration. The article at
> kuro5hin.org compares C++ to ML and Scheme, both quite away from
> mainstream. That makes its criticism very much theoretic, for noone
> is really proposing a switch. In contrast, a swtich to Objective C
> is real.
>
> That's why I support the idea of an article that would stress the
> power of Objective C versus C++. Objective C promotion can help to
> make it as widespread as should be.
I think the difference is between dynamic and static languages. Lisp
Objective-C or Smalltalk are dynamic, the type of the value is known
at run-time (stored along with the value). C++ can be used, and is
most often used for fallacious performance reasons, as purely static,
with the type only known at compilation-time. Hence the need for
template. But personally, I've never used template in C++, because I
only use virtual methods, and all my objects are used by reference,
like it is in Objective-C, and invisibly in Smalltalk and Lisp. Then
the type (the class) of my values are known at run-time, and I can
have a single BpList class holding BpObject instances. Of course,
it's still slightly less dynamic than Objetive-C, and I have to type
cast the elements of my list before being able to send them a message,
but that's not too big a problem. At least, it does not seems to be
as problematic than templates... So, with the implementation of a
couple of methods in a root class, and the addition of a 'class'
class, you can almost get an Objective-C in C++. (Greenspun's tenth).
CONSTRUCTOR(BpObject)
DESTRUCTOR(BpObject)
METHOD(BpObject,makeBrother,(void),BpObject*)
METHOD(BpObject,runtimeClass,(void),BpClass*)
METHOD(BpObject,superClass,(void),BpClass*)
METHOD(BpObject,className,(void),const char*)
METHOD(BpObject,isKindOf,(const BpClass* aClass),BOOLEAN)
METHOD(BpObject,isKindOfClassNamed,(const char* aClassName),BOOLEAN)
METHOD(BpObject,isMemberOf,(const BpClass* aClass),BOOLEAN)
METHOD(BpObject,isMemberOfClassNamed,(const char* aClassName),BOOLEAN)
METHOD(BpObject,retain,(void),BpObject*)
METHOD(BpObject,release,(void),BpObject*)
METHOD(BpObject,retainCount,(void),INT32)
CLASSMETHOD(BpObject,processDeletePool,(void),void)
METHOD(BpObject,dependantCount,(void),CARD32)
METHOD(BpObject,dependantAt,(CARD32 index),BpObject*)
METHOD(BpObject,dependantAdd,(BpObject* nDependant),void)
METHOD(BpObject,dependantRemove,(BpObject* nDependant),void)
METHOD(BpObject,dependantRemoveAt,(CARD32 index),BpObject*)
METHOD(BpObject,selfChanged,(INT32 cause),void)
METHOD(BpObject,dependeeChanged,(BpObject* dependee,INT32 cause),void)
C is the assembly language of procedural languages. C++ is the
assembly language of object oriented language. When you compile a
high level language into assembly, you don't use all the
micro-processor instructions just for the thrill of it. You just use
the micro-instructions you need to implement cleanly your high level
constructs. So when you program in C++, don't use every feature C++
has!
--
__Pascal_Bourguignon__ http://www.informatimago.com/
----------------------------------------------------------------------
Do not adjust your mind, there is a fault in reality.