Why is tcl broken?
greg.ewing at compaq.com
Wed Jun 16 19:05:55 EDT 1999
Fernando Mato Mira wrote:
> I wanted to find out whether the disgust for tcl I've seen many people
> express had some basis on some generally accepted principles.
I think I can give some reasonably objective reasons why
I find that I enjoy using Python in a way that I don't
enjoy using Tcl. (I have used both, and in one case have
written versions of the same program in both languages.)
Tcl's syntax is based on the principle that an unadorned
sequence of alphanumeric characters represents a literal.
Anything else (such as referring to a variable) requires
Ousterhout's justification is that this is optimal
for entering commands interactively, which is probably true.
However, this seems to me the wrong thing to optimise for,
given that tcl is meant to be a *programming* language.
The case being optimised for -- typing in a command which
is to be used once and thrown away -- simply doesn't occur.
Programs, even tiny ones, get used more than once!
In my opinion, the small amount of extra syntax needed
to quote literals and express function calls in a language
like Python is well worth the benefits you get further
down the track. An example of these is that, where in
Tcl you find yourself writing
set a [expr $b + $c]
in Python you get to write
a = b + c
Since the vast majority of words in my programs refer
to variables, and string literals are relatively rare,
I much prefer the Python way of writing things to
the Tcl way.
2. Data structures
Briefly, Python has them, Tcl doesn't. Tcl has character
strings, which are sometimes interpreted according to a
certain set of rules as lists of other character strings.
The rules are pedantic and can trip you up sometimes.
Tcl also has associative arrays, which is a powerful
feature compared to what some languages give you, but
they're not first-class objects and all you can put
in them are character strings.
Python has a rich set of first-class data types, including
lists, dictionaries (associative arrays) and classes/instances,
from which you can build real data structures and manipulate
them in easy and intuitive ways.
Tcl proponents will tell you that you can emulate all of
that using tcl lists and arrays, which is true, but misses
the point. Why bother with emulation when you can have the
real thing at no extra cost?
In my experience, I find that I can do with Python everything
that Tcl was designed for, do it more easily, do a lot
more besides, and have more fun in the process. I believe
the reason for this is rooted in some fundamental design
features of these languages, which I have sketched above.
I think that's about as close as one can get to providing
an objective argument as to whether one language is better
than another for a given purpose.
More information about the Python-list