Information about object-oriented programming and Tcl
Object-Oriented Tcl is a magazine article from July 2004 that introduces the subject for those unfamiliar with Tcl.
EG 2009-09-20 The above link is unavailable. gkubu 2012-06-03 Try [L1 ] (loading may take some time)
See the TclOO framework which is a part of Tcl 8.6. It is also available as an extension for 8.5.
Discussion - what do you mean when you say "Object orientation"? What must be present for a programming language to be considered OO to you?
When I say "object orientation", I refer to Grady Booch's definition: Object-oriented analysis and design's underlying concept is that one should model software systems as collections of cooperating objects, treating individual objects as instances of a class within a hierarchy of classes. I expect the ability to define my own hierarchy of classes (inheritance), where the classes define objects' data and behavior, and I expect the ability to separate interface and implementation. - RWT 10/30/00
"Objects in Tcl" [L2 ] by Koen van Damme gives a guided tour of creating pure-Tcl objects without inheritance. See also Gadgets, LOST, and MOST. For a minimal pure-Tcl OO system that allows (but not requires) to distinguish objects and classes, see On things - Doing things in namespaces - Chaining things. In yet another weekend, RS has been playing OO. See also playing oo design.
DKF: Fundamentally, OO in Tcl means that you've got an ensemble-like command (i.e. a command with subcommands) and some internal state model associated with that command (and manipulated by the subcommands) that goes away when the object is destroyed. That's all that's required. Everything else (including classes) is optional, if often useful to have. Note that according to this definition, Tk uses an object system for its widgets.
wdb: The benefit of object orientation is doubtlessly its information-saving and hiding capability. Possibly oo is mainstream nowadays. If a language is purely object-oriented such as Ruby, then it is ok. But oo is not the one true solution. If a language has a different paradigma such as Tcl and others, then it's nice to have the opportunity to use oo, but not to forget that there are other mechanisms of information hiding. I have used both, Itcl and Snit, and both do a good job in their way, but in some cases I prefer more language-generic mechanisms such as procedures originated in namespaces where they have private information as well. The true benefit of Tcl is imho the opportunity to use more than one oo extension in one application. This makes Tcl unique compared with the other scripting languages.
Since the comprehensive list (below) has grown very long, here is a short list (in no particular order) of some OO frameworks that are in very widespread use.
What Tcl extensions attempt to provide some framework of OO support? For each extension, add info about what features make this extension unique. Also, add information regarding the level of support available for the extension. Finally, add URLs for the extension as well as for some practical uses for the extension.
Some of these frameworks are intended for general-purpose deployment; others were developed to satisfy the requirements of a specific project. Some of these frameworks are no longer maintained.
Category Object Orientation lists several other projects that use a minimum of code to provide a subset of object-oriented facilities.
What: Tclpp Where: http://www.geocities.com/SiliconValley/Network/2836/projects/tclpp/ Description: Tcl 8 based object oriented extension. Provides Java or C++ object syntax to Tcl. Adds items like multiple inheritance, data encapsulation, virtual functions and RTTI (Run Time Type Info). Currently at version 2.0. Updated: 06/2000 Contact: mailto:[email protected] (Stefan Sinnige) What: Tclaop Where: http://www.eriskouma.com/default/all/en/tclaop.html Description: Aspect Oriented Programming extension (experimental). Based on the good work of stefan Sinninge Tclpp (version 1.2, pure tcl script). Updated: 11/2002 Contact: [email protected] What: Tea Where: http://members.xoom.com/iliadtools2/tea/ http://members.xoom.com/iliadtools2/tea/tea-3.0.tar.gz Description: Tcl 8 based object oriented extension. Tea follows the Java model, trying to implement the look of Java from a class definition perspective, yet remain syntactically consistent with Tcl. Written in Tcl 8 source code. Classes can be put into a zip archive. Updated: 02/2000 Contact: mailto:[email protected] (John Stump) What: theObjects Where: ftp://ftp.procplace.com/pub/tcl/sorted/packages-7.6/devel/theObjects-3.1.tar.gz -- procplace is gone Description: Small prototype-oriented object system. Updated: 10/1998 Contact: mailto:[email protected] (Juergen Wagner) mailto:[email protected] (Juergen Wagner) What: this Where: From the contact Description: An easy way to build Tcl objects. Contact: mailto:[email protected] (Charles Ballance) What: TODL Where: http://users.pandora.be/koen.vandamme1/tcl_tools/todl/todl.txt http://users.pandora.be/koen.vandamme1/tcl_tools/todl/todl.tgz Description: Simple library and tools for object support in Tcl. Updated: 12/2000 Contact: mailto:koen.vandamme1 at pandora.be What: TOS Where: http://www2.lifl.fr/%7Epawlak/tos Description: Tcl Object System (TOS) is another Tcl extension for object oriented programming, this one having full reflectiveness. Contains special objects called Class, Metaclass, and Object that control the base object behavior and devinitions. Currently at version 2.3.1 . Updated: 11/2006 Contact: mailto:[email protected] (Renaud Pawlak) What: TWO - Tcl With Objects Where: ftp://ftp.procplace.com/pub/tcl/sorted/packages-7.6/devel/tclwobjects1.tar.gz -- procplace is gone Description: Tcl-based simple objects. Instance variables are accessed just like local variables. Updated: 10/1998 Contact: mailto:[email protected] (Andrew Ginter) What: [XOTcl] Where: http://www.xotcl.org/ http://media.wu-wien.ac.at/ Description: Extended OTcl - exotickle - is a value added replacement of the MIT OTcl object extension. In addition to all the OTcl bonuses like meta-classes, multiple inheritance and read/write introspection, XOTcl adds Per-Objects Mix-ins, Filters, Nested Classes, Dynamic Object aggregations, metadata and assertions. All of these features together allow easy construction of high-level patterns and structures and simultaneously follow the Tao of Tcl. Updated: 06/2001 Contact: mailto:[email protected] (Uwe Zdun)
Yet another object system does everything with lists. Procs as objects does it with default arguments to procs, instance variables might be kept in alias only.
SDynObject is a pure Tcl system that is very simple and extensible.
TOE -- Toe is an extension to the Tcl programming language that enables object-oriented (OO) programming in a class-based, Java-like style. Toe provides commands that allow a Tcl scripting programmer to create OO classes, define functional relationships between classes, run Tcl code in objects created from the classes, and implement various multiple-class patterns that are well-known in the object-oriented paradigm.
A lightly annotated index to most of the same packages appears at [L3 ].
The community would benefit greatly from even the most rudimentary OO benchmarking project. Miguel Sofer points out that Doug Bagley's "Shootout" [L4 ] includes "Object Instantiation" and "Method Calls" items which might to inspire Tcl-specific designs.
SLB You mean like Comparing Performance of Tcl OO extensions?
Tcl appears ambivalent, at best, about object orientation. Darren New has suggested that "the need for OO techniques is greatly reduced by a language with eval and info and dynamically-sized structures built in." DKF finds subclassing for GUI configuration suboptimal.
John Buckman has written a tiny (<100 lines) OOP toolkit called BOOP (for "Basic OOP") which is super-simple, aimed at people who want a small amount of object oriented functionality (objects, member functions, memory cleanup, member vars) implemented in simple, comprehensible Tcl that won't gum up your environment, complexify your debugging or break debuggers.
In 2001, Mike Rogers wrote a "cute and fuzzy" pure-Tcl extension that endows namespaces with inheritance [L5 ].
See also Writing Extensions and, in an entirely different direction, RS's many demonstrations, including "Playing with Circuits", of how OO can be a stylistic matter, without syntactic scaffolding.
See also:
Kristoffer Lawson (aka setok) has made a package of his Selfish object system, done in pure Tcl.
See TIPs:
for some of the history of proposed object orientation for Tcl.
See thoughts on implementing OO in tcl.