DEV Community

George Jempty
George Jempty

Posted on

What 100 Lines of Tcl Code Can Accomplish

Just three years into my programming career I was already a bit of a polyglot, having started with Progress 4GL but then quickly moving on to technologies more recognizable today including Javascript, Perl, Python, ASP, etc. So when I took a job at a hospital and learned they used a data format called HL7 which was scriptable with Tcl I decided to learn a bit of Tcl on my own.

To that end I undertook one of my favorite first exercises when learning a new language, and this is to convert numbers to Roman numerals. While still pretty trivial, my solution at least involves looping and arithmetic, a lot more than can be said for "Hello World." Here's my "recipe" dating back to 2001.

I never did get to use Tcl at that hospital, and despite continuing to occasionally dabble with it over the rest of that decade, I never did (and still haven't to this date) get to use it professionally. Still though, my interest in one of the technologies associated with Tcl would pay off for me, at least on a "self actualizing" level, as the next decade began.

As a web developer I was drawn to the tclhttpd web server. And though a lot of people would say, and would probably be correct, that one of the most important facets of Tcl was it's close integration with the cross-platform GUI toolkit Tk, but again, as a web developer, I obviously was already targeting the browser as the UI.

No, what I found especially interesting about Tcl was a toolchain including the following:

  • tclkits
  • starkits
  • starpacks

A tclkit "is a compact, single file executable containing a complete scripting runtime, including a rich scripting language (Tcl)", etc.; see: https://equi4.com/tclkit/ And compact means just a megabyte give or take, depending on whether Tk is included or not.

A starkit "is a single-file packaging of a directory hierarchy containing Tcl scripts, platform-specific compiled code, and application data. A starkit leverages Tcl's virtual filesystem....(they) facilitate simple deployment of cross platform applications." See: https://wiki.tcl.tk/3661

Further: "A starkit can be run ... via a Tclkit:"

mytclkit mystarkit.kit

So the pieces are starting to come together. Already this makes it so much simpler to distribute some script than what a lot of applications sometimes require, which is to install (on Windows) full-blown Perl or Python that isn't already there, to then run their code.

But there's the piece de resistance, starpacks: "A starpack is a single executable file which contains both basekit (which includes tclkit) and a Starkit"; see: http://wiki.tcl.tk/3663

Close to the end of last decade I was contracting somewhere I actually got to use my own PHP micro-framework -- that's another story ;) But something we needed to do in the course of my work there was embed an ftp client in a web page, due to the need to move around files larger than 2GB. Immediately we though of a Java applet, and that is what we indeed settled upon, but somewhere along the line I'd heard of Adobe AIR, so suggested that we at least evaluate what it could do for us.

Despite not using AIR, I was intrigued by its possibilities and put it in the back of my mind, and a year or so later it struck me that what made it possible to develop desktop applications with web technologies would be to:

  1. Launch a local web server
  2. Point a stripped-down browser (no location bar for instance) at the content being served

And given everything I've written so far, as soon as I came to the above realization, in my head I put together the entire Tcl-based stack necessary to achieve something similar (web server, the language interpreter, tooling to create an executable) with one missing element: the web browser.

And I found it! See https://wiki.tcl.tk/3134 but particularly https://wiki.tcl.tk/17697: hv3

Once I had my entire stack everything fell into place very quickly and I was able to come up with a rough prototype equivalent to Adobe AIR in my spare time on weekends. Actually instead of using tclhttpd I used an easy to grok 400-line server written by the same person uhttpd. Then between the necessary code modifications I made to it and the hv3 browser, and then the necessary code for launching the starkit, I only had to touch approximately 100 lines of code. The results of my efforts, which I dubbed "DeskML", can be found at the Downloads link here: https://code.google.com/archive/p/deskml/

I never went terribly much further with the platform though. If I recall there were issues running it on new 64-bit versions of operating systems. Also HTML5 was coming out and hv3 was not compliant. And today there are other alternatives that have supplanted Adobe AIR, nwjs (NodeWebkit) and even more so, Electron.

Still though, Deskml is probably the one thing in my nearly 20-year software development career that I am most proud of. And I couldn't have done it without Tcl!

Top comments (0)