Wize /
Obj Commands
Search:  

Object-Commands

An object-command is a command created by calling an instantiator. eg:

  text .t; # Creates text widget command .t
  set i [image create photo]; # Creates photo image command

As the name implies, object-commands carry along with them a data context.

The Problem

A big problem with object commands is that the Tcl compiler can not possibly validate them. Such commands are usually assigned to variables, and therefore code ends up with zillions of calls like:

  $w1 insert end "Start"
  $o1 conf -state normal
  $im blank

Thus it is very difficult to tell (both for the compiler and the maintainer) what the above code is doing, and if it is correct.

Languages such as C++ can manage this reliably because objects are part of the type system. Thus the compiler can warn developers of improper usage. Tcl however has no types per-se and thus the user is given no warning of a problem, until the code is executed.

The lack of types (in the context of object-commands) makes Tk applications very difficult to maintain.

The Solution

Wize remedies this by implementing alternative, non-object commands for widgets, images etc.

Thus using these, the above can be rewritten as:

  Text insert $w1 end "Start"
  Entry conf $o1 -state normal
  photos blank $im

This makes it readily apparent (to later maintainers) exactly what was intended by each command. Moreover, when run with wize -Wall the Tcl compiler can validate the following:

  • Text has a sub-command insert with the given args.
  • Entry has the sub-command conf with a -state option.
  • photos has a blank sub-command.

© 2008 Peter MacDonald

Page last modified on June 11, 2009, at 06:47 PM