Version 48 of XOTcl

Updated 2005-10-09 15:41:15

This is a page for information, tips and hints about the XOTcl object-oriented extension.


Partly taken from the XOTcl homepage [L1 ]:

XOTcl combines the ideas of scripting and object-orientation in a way that preserves the benefits of both of them. It is equipped with several new language functions that help building and managing complex systems. It supports the following features:

  • Dynamic Object Aggregations, to provide dynamic aggregations through nested namespaces (objects).
  • Nested Classes, to reduce the interference of independently developed program structures.
  • Assertions, to reduce the interface and the reliability problems caused by dynamic typing and, therefore, to ease the combination of many components.
  • Per-object mixins, as a means to improve flexibility of mixin methods by giving an object access to several different supplemental classes, which may be changed dynamically.
  • Per-class mixins, as a means to improve flexibility of mixin methods to a class, all instances of the class have access to the mixed in methods like for multiple inheritance, but without the need of intersection classes.
  • Per-class and per-object filters, as a means of abstractions over method invocations to implement large program structures, like design patterns.
  • Dynamic Component Loading, XOTcl integrates the Tcl package loading with architectural support for integration with object-oriented constructs. Moreover, it provides tracking/tracing of component loading.
  • Dynamic read/write introspection and extensibility.
  • Meta-classes.

XOTcl is now part of ActiveTcl [L2 ] and is included in the "Batteries included" version of the Aqua distribution for Mac OsX [L3 ].


Zoran Vasiljevic describes: "... it runs leak free, does not crash, obeys to what's written in the manual, is thread-safe, can be used under AOLserver or under Tcl threading extension w/o problems, is loaded with features., checked with Purify... ... We have written 100K lines in Xotcl and I find it very valuable. I like it more than incrTcl since it ihas more of the dynamic nature of Tcl than incrTcl does. The incrTcl is more appealing to c++/java programmers. Xotcl should be more appealing to Tcl programmers, IMHO."

IL How does XOtcl work with an existing aolserver application?


XOTcl is thread safe (see Thread-safe Tcl Extensions) and one of the fastest OO Tcl Extensions (see Tcl OO Bench).


Gustaf Neumann GN writes to the XOTcl mailing list [L4 ] on 20Jul03:

...let me re-iterate the basic "philosophical" point of view. Languages like xotcl are object-oriented, while languages like java (and most of UML) is class-oriented.

Class-oriented means: look at the class and you know exactly how all of the instances look alike. The class is the first and primary language construct; the class is well the place where you specify the instance variables (there are no instance variables except those specified in the class). The only kind of individualism left in the objects is to let them differ by their state (the values of their instance variables). Changing classes (class migration) is conceptionally quite hard for this setup.

Object-oriented (in this distinction) means that the primary elements are objects, which keep all instance variables. classes my be used to specify the behavior of objects, they are container for methods and they control the life-cycle of objects. Objects are like the facts, and classes are like rules, that determine the behavior of the objects. Since the connection between objects and classes is rather loose, it is sufficient to define their relation through an association. Therefore it is quite easy to change the relation between objects and classes (and between classes and classes) dynamically. Objects have arbitrary individualism, they may have variables never used in any class, they may have private procs etc.

From the expressiveness, object-oriented languages can - in principle - be restricted to behave like class-oriented languages, but the other way around is much harder.


Useful code tidbits:

Comparison with other Tcl OO Extensions:


See also XotclIDE, XOTcl Documentation Tool, Learning XOTcl, Object Orientation. You might be interested in the French Wiki pages about XOTcl and XOTclIDE [L6 ].



NEM 18Apr2004: I guess a question which comes up with any object system eventually is "has anyone written a mega-widget framework with this yet?" It seems to me that XOTcl is a pretty powerful object system, and so could probably form the basis of a very nice widget framework. Has anyone done any experiments in this direction? How would you go about it? Create a new meta-class type construct (Widget or something like that)? Doing something like this as an exercise might be a useful way to show off some of the more powerful features of XOTcl, and how they can be used to good effect.

Artur Trzewik 19Apr2004: There are pretty many GUI Stuff in XOTclIDE in component IDEBaseGUI. It is not complete GUI Framework but some special classes that offer OO way to use Tk. For example Menu-Framework that can control automatic menu enablement and same time pop-up menus. Also

  • Standards Dialogs. Entry Dialog, List Chooser, ...
  • Framework for modelles Dialogs
  • Editor Widgets (with save callback, file open and save)
  • List dialog class that can be used by inharance to programm own logic (the way it was used in XOTclIDE)

Indeed XOTcl works pretty good with another Widgetsframeworks. I have used Tix and BWidget without problems. Even ITk is possible (but not tested be myself).

WHD 23Apr2004 Artur, I think you're describing a collection of widget-like objects written in XOTcl; what Neil was asking about was a straightforward means of creating new widgets in XOTcl, rather like snit::widgets which work like and interoperate with Tk widgets. So let me ask the question a different way--using XOTcl, is it possible to create an object that looks and acts like a Tk widget?

Artur Trzewik 23Apr2004 - Yes it is possible to create Tk like widgets with XOTcl (the same do Tix or ITk). But you not really want it. Because Tk is not realy OO (it has some OO characteristic because options by some widget has the same name). You can not bild child class to button or text Tk widget but it were base technique for OO widget set. Therefore realy OO-Widget SET would wrap Tk widget and not build some new Tk-like widget.

XOTcl widget set should be more like WinForms from .NET, Qt or Java Swing. For Example with XOTcl is posible to use more programm techniques than Tk offer it. One problem of adapting Tk to OO is lack of events (���Publisher-Subscriber��� Modell) that is usefull form implementing Modell View Controller Pattern. In this case you must wrap Tk in XOTcl-Classes and programm it yourself. Another tasks were: Validators, Buffering, Building from XML.

Some techniques of using Tk in XOTcl was also discussed in XOTcl mailings see http://alice.wu-wien.ac.at/pipermail/xotcl (I do not remember the month) [L7 ]

The question is what to you want achieve with XOTcl widget set.

   - new Tk widgets (XOTcl is hidden from user)
   - Tk megawidgets (XOTcl is hidden from user)
   - OO Widgetset with OO Techniques (Modell View Controller). Not Tk specific

For me Tk is good base widget set. But in OO-Application you will rather wrap them to your classes and adapt them to your OO-use specific for your application. The advantage of XOTcl is not the possibility to build new Tk-Widgets but rather use them in OO-manner.


Strick 11jan2005 -- Does anyone have hints on using XOTcl in a safe interpreter? It doesn't have a Xotcl_SafeInit(), so you can't load it. Aliasing it from a full interpreter is a bad idea: "Object eval" would give you access to the full interpreter. It looks like I'll have to do surgery on the sources? This paper [L8 ] makes me think it's been done before.


SYStems Does anyone know where I can get recent debian packages for XOTcl? Sarge doesn't have any XOTcl packages at all


Category Object Orientation | Category Package