Untitled Document User Interface Software Tools Course


HOME | Lectures

A Tcl style guide.

General

These are some general rules that actually apply to any programming language, not just Tcl.

Formatting

Luckily, Tcl doesn't offer very much leeway in where braces are put. So hopefully this will be a lot shorter than the corresponding guide for C.

Comments

Comments are one of the trickier parts of Tcl. Unlike most other languages, the comment leader, ``#'', only introduces a comment at command-execution time. This has caused untold confusion (including a bug in the scripts that come with Tcl itself).

Quoting

Another confusing aspect of Tcl is commonly referred to as Quoting Hell. But as with other kinds of Hell, you only end up there if you try.

Clarity

The Compiler

Tcl 8.0 includes a reimplementation of the internals so that Tcl scripts are now byte-compiled and run by a bytecode interpreter. This promises to give a large performance boost. It also has some implications for Tcl style.

Tk

By far the most important guideline for using Tk are User interface Design rules. Tk specific rules are:

Naming conventions

Variables and procedures:
myProc or MyProc
countNum or CountNum
Variables holding Tcl code (intended for eval) ends with Script:
logScript
Variables holding parts of Tcl commands (intended for eval) ends with Cmd:
myCmd