Hands-On: Using Tcl as Application Glue for the Enterprise

You may know Tcl, and think of it as one of those “toy languages” that teenagers can pick up in less than an hour and make little GUI programs, chat scripts, and primitive Web pages. But Tcl is also finding broadening appeal among enterprise developers facing complex and costly integration projects, as an “industrial strength application glue”.

In the article below, we’ll explain more about Tcl’s use as “industrial-strength application glue,” and show you just how Tcl is becoming a not-so-secret-weapon for developers working on integration projects at such high-profile sites as Oracle, IBM, Cisco, NASA, TiVo, America OnLine, and even the CIA.

We’ll also show you how Tcl can be used by a broad spectrum of developers. Whether you’re working with Java, C#, C++, XML, Fortran or even SQL, Tcl may be able to offer some options because it has been written — and expanded upon — to talk to all these environments already.

Tcl as Strong Glue
Tcl indeed began its life, toward the end of the ’80s, as something less than, or at least different from, a general-purpose programming language. John Ousterhout, then a professor at the University of California at Berkeley, created it as an “extension language” or “scripting language” library.

Tcl was designed to be embedded in computer-assisted design (CAD) applications, mail agents, and other complicated programs that demanded flexibility and plenty of configuration. In the early years, Tcl’s design emphasis was on error-free operation, and ease of porting and interfacing with other programs. The Tcl language itself was deliberately kept quite simple.

By the mid-90s, Tcl’s scope had expanded — offering developers a general-purpose language with handy interfaces for networking, graphics, Unicode-savvy text manipulation, and more. Through the evolution, Tcl remained highly portable, with good versions available for MacOS, Unix, OpenVMS, Windows, and other operating systems (OSs). It’s still robust, hard to “crash”, simple to learn — it has no keywords! — and good at combining with other programs.

Which brings us to the IT challenges of the early 2000s, and Tcl’s continued evolution. Today, IT departments are grappling with “enterprise-class” software that only plays nicely with its closest friends. Much of the enormous cost and risk of using and customizing enterprise software development — CRM, ERP, Web portals, document managers, etc. — has to do with their clumsy interfaces.

Consultants have been able to specialize in just one such package, because there’s so much work involved in tying its data in with the other systems an organization needs. But, that kind of specialization seldom meets the exact needs of customers — and so we have an “integration gap” in many enterprise software deployments.

How the Tcl Approach Differs from Java
For many years, enterprise developers looked to bridge this “integration gap” using Java and its supporting libraries. Java’s answer to such realities has been to try to bring all solutions inside the language. Java aims to have the right syntax and right libraries for all problems.

While Java has had much success, Tcl takes almost the opposite approach. Tcl’s strength lies in being open to anything outside itself that already solves a problem. That’s part of the reason Oracle and IBM chose Tcl when developing their Oracle Enterprise Manager and WebSphere Control Program server administrator products, or why Cisco makes so much use of Tcl in the firmware for its network devices. Also, these reasons help explain why AOL’s high-performance AOLserver is scripted in Tcl, and the reasons that that even NASA laboratories rely on Tcl for construction of portable user interfaces

Many Tcl programmers find the language so congenial, and the libraries it has accumulated in the pat few years so powerful, that they focus on Tcl as a general-purpose development language. Thousands of production applications have been documented as written exclusively, or nearly so, in Tcl. These include such substantial projects as a million-line test suite at Sybase, and a Benefit Central program of WebMD.

In fact, for a wide variety of legacy systems,, Tcl may offer options. As mentioned above, Tcl already talks to Java, C++, Fortran and XML systems, among others. When you have data here— that needs just a little bit of massaging before its displayed elsewhere, Tcl can offer many developers a complement to the development tools they use now because Tcl is at its best in “putting the pieces together”. In the section below, we’ll let you build your own small “Tcl Test Drive” and you can see for yourself.

A Tcl Case in Point
What’s it mean “at ground-level” to exploit Tcl as “flexible glue”? While many companies stay close-mouthed about their successes (because they don’t want customers or competitors — or upper management! — to know they do in two days what otherwise would take two weeks), we can offer one true Case Study.

John Guineau, a systems software engineer at NASA’s Jet Propulsion Laboratory, provides one illustration that’s concrete, small enough to be comprehensible, but important enough to matter. He’s part of the team responsible for ground-control software for the Jason-1 scientific satellite. This is a project completed on schedule and under budget. Moreover, Guineau said, Tcl gave it many new capabilities beyond those originally required.

The system specification for a satellite control system is in terms of “hands-on” operation: when it’s time for an operation to occur, a trained technician performs a sequence of points-and-clicks. Guineau’s team attached a Tcl interpreter to its Java-coded services, though. This provided a textual “handle” on all the internal workings of the application.

The result: satellite control is now completely “scriptable”. Below is a sample example of a routine that even managers, Guineau said, can code up. This simple script makes possible, not just such frills as satellite control on wireless hand-held iPaqs, but entirely “lights-out” operations for indefinite periods. Tcl’s textual complement to the normal user interface makes the system more auditable, more robust, and open to further automations.

   proc main { } {

        set rc 0


        # First make sure all Cm connections are gone

        jtcc cm abortall

        jtcc wait 500


        if {[setSatId 80] == 1 &&

            [setTcMode BD] == 1 &&

            [enableCommanding ENABLE] == 1 &&

            [connect] == 1} {


            # At this point we are initialized and connected to the BVO

            # Wait 60 seconds and terminate connections

            set endTime [expr [clock clicks -milliseconds] + 60000]


            # Name of TC File to translate and transmit

            set tcFile 10nop


            # Translate the file

            if {[translateCommand $tcFile TranslateBinaryOnly] == 1} {


                # Now transmit the translated file

                if {[transmitCommand $tcFile] == 1} {





        return $rc


Make Your Own Tcl Test Drive
Now, if you want to see for yourself if Tcl might work for your specific project, it’s quite simple. With an investment of one hour (and no cash), you can download, install, and learn enough Tcl to write meaningful small programs. In fact, it’s traditional among Tcl development teams to license Tcl-related code under particularly liberal terms: do anything you like, just don’t claim copyright for what others have written. That liberality has only encouraged Tcl’s use in the embedded software of vendors including Cisco and TiVo.

The core Tcl processor is wrapped in several different installable forms. This is something like the range of different Java Virtual Machines (JVMs), within and across different platforms. For your first encounter with Tcl, download the ActiveTcl appropriate to your desktop; you’ll find this at a URL below.

Install ActiveTcl. The tutorials below will show you how to write a “Hello, World”. Let your second program be a bit more substantial: a small GUI which accesses a Web Service to retrieve the current temperature at different locations. Here’s what you’ll see when you run the script:
[Figure 1]

To achieve this, you only need a few lines of Tcl code:

      # Declare required libraries.

  package require SOAP

  package require Tk

      # Create a simple GUI display.  Bind the entry display

      #    to "zipcode".

  entry .my_entry -textvariable zipcode

  label .my_label

  pack .my_entry .my_label


      #    describes this service.

  set URI urn:xmethods-Temperature

  set URL http://services.xmethods.net/soap/servlet/rpcrouter

      # Bind a local command to the remote service.

  SOAP::create getTemp -uri $URI -proxy $URL -params {zipcode string}

      # Invoke the SOAP-mediated local command when the user

      #    pushes the "Return" key.  Display the return value.

  bind .my_entry  {

      .my_label configure -text \

          "The temperature at $zipcode is [getTemp $zipcode]."



Compare for yourself the readability of this example with what it takes to access GUI and SOAP services in other systems you know.

Upcoming Tcl Conference
One final reason it’s timely to learn about Tcl is the imminent Tcl Annual Conference(September 16-20), produced by the Tcl Developer Xchange and hosted by ActiveState. Tcl’s “light-weight” character is evident even in the schedule for this conference: prices for accommodation and tutorials are considerably lower than are typical for Java, XML, or vendor events. As usual, the Tcl team has chosen an “off-peak” approach that emphasizes getting more done with less.

Cameron Laird is vice president of Phaseit, Inc., where he specializes in Rapid Enterprise Integration consulting. He frequently gives tutorials on uses of scripting languages, and has contributed to dozens of “open-source” programming projects, including several in the last year which bind Tcl to web services.

More Resources and Links for Tcl 
The Tcl Developer Xchange provides a one-stop resource for new and seasoned Tcl users, including the latest releases, documentation, mailing lists and code samples using Tcl.

* ActiveState’s ActiveTcl is a “quality-assured” binary build of Tcl, available for Linux, Solaris and Windows. As part of the company’s support for Tcl, ActiveState provides these ActiveTcl binary packages free to the community. ActiveTcl can be downloaded or installed from here.

* This article in Unix Review magazine shows how a little Tcl code can achive a lot. The main subject of this profile, Richard Suchenwirth, is planning a book which illustrates important algorithms and computing principles with Tcl employed as “executable pseudo-code.”

* Another great place to start with Tcl is this website, entitled: “In the beginning – first stop for someone new to Tcl and Tk” The site includes an overview of Tcl, beginning Tcl with code samples, a “User’s Guide to Tcl and Tk,” and a libray of other interesting and useful Tcl links.

“Scripting: Higher Level Programming for the 21st Century” is Tcl creator John Ousterhout’s explanation of how he sees Tcl’s role.