Re: True Inheritable Classes In C (was Generic Interface)

Tako Schotanus (sst@bouw.tno.nl)
Thu, 9 Mar 1995 09:47:36 GMT

In article <2F5F8A20@dayna.msmail.jm.cmutual.com.au>, "Hammond, Mark" <MHammond@jm.cmutual.com.au> says:

>Going the full way to _really_trully_true_ inheritance is probably a pipe
>dream.
>
>Regards,
>
>Mark (MHammond@cmutual.com.au)

I just read an interesting article in the tcl newsgroup, maybe
one of you could get some ideas from this one? It's about a tight
integration of an OO extension to Tcl and C++. Article included:

------------------------- start of included article ---------------------

Hoshi Takanori wrote:

> I just posted a question: What is the difference between Object Tcl and
> [incr Tcl]? Especially, I want to know if otcl is faster than itcl, and
> if it is easy to port itcl scripts to otcl.

Object Tcl faster than [incr Tcl]?

Well, the first implementation of Object Tcl incurred about 60% LESS
than the [incr Tcl] overhead but it turns out that the overhead of both
Object Tcl and [incr Tcl] is very small compared to the Tcl consumption.

B1.0 of Object Tcl is a complete re-write and I haven't performed any
comparisons between Object Tcl and [incr Tcl] but I would expect
it to have changed too much.

As Object Tcl is designed to support inheritance from C++ (see
below) classes then it becomes trivial to move classes into C++ for
performance gains.

The general differences are:

o Object Tcl is designed to support the specialisation of
C++ classes in Tcl (OO Tcl that is).

a C++ class like:

class Animal
{
public:
virtual void makeNoise (void);
void foodTime (void);
};

can be exported to the Object Tcl system using a
class description of

class Animal {
method makeNoise -dynamic {void} {void}
method foodTime -static {void} {void}
}

Animal C++ class and the C++ code generated by the Object Tcl
CDL processor can be linked with tclsh and then:

otclInterface Dog -is Animal {
method makeNoise {}
}
otclImplementation Dog {
method makeNoise {} {
puts "Bark, bark"
}
}

%set a [otclNew Dog]
%$a foodTime
Bark, bark
%

If the $a object was passed back into C++, C++ could call
a->foodTime() and "Bark, bark" would still be printed.

o Object Tcl supports management of C++ classes.

From the example above in Tcl you could
% set a [otclNew Animal]
% $a foodTime

o Object Tcl makes it trivial to export C++ classes
to Tcl.

o Object Tcl is a standard extension to Tcl, it can even be
dynamically loaded (after a little hack on the Beta, next
version should support it directly).

Is it easy to turn [incr Tcl] classes in Object Tcl classes?

Well that depends on how many unusual features of [incr Tcl] you use.
Object Tcl supports all of the standard OO concepts but its syntax is
obviously different from [incr Tcl]. [incr Tcl] provides some features
that wouldn't be considered standard OO. For example, the configure
method on [incr Tcl] classes.

I haven't tried to port an [incr Tcl] script to Object Tcl.

Finaly, Object Tcl is not pitched as a replacement for [incr Tcl] but if
you want cool C++ integration...

- Dean

___________________________________________________________________________
__ __ __ __
| |\ / /| | Dean Sheehan Vision Park Email: deans@x.co.uk
| | \/ / | | Software Architect Cambridge
| | / /\ | | CB4 4ZR Tel: +44 1223 518034
|__|/__/__\|__| IXI Limited England Fax: +44 1223 518001
___________________________________________________________________________

--------------------------- end of included article ---------------------

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ Tako Schotanus TNO Building and Construction Research _/
_/ Phone : +31 15 842393 Fax : +31 15 122182 E-mail : sst@bouw.tno.nl _/
_/ My employer is required,by Dutch law,to disagree with whatever I say _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/