October 20, 2004

10 Things I Hate About Tcl

by peterb

I really, really, really don't like Tcl. Here are some of the reasons why.

1. The syntax for basic language elements is broken and inconsistent. Look, go ahead and put dollar signs in front of variables. Or don't put dollar signs in front of variables. I don't really care. But make up your mind; don't make me have to figure out which syntax I need to use from context.

2. No syntax checking until the program actually executes a given line of code. Look, guys, maybe this made sense twenty years ago when you were running on a DECstation 2100, but those few extra milliseconds really aren't going to kill us. Conversely, the interpreter is forced to reparse all syntactic blocks (for loops, if statements, and so on), every single time they are executed. So you spend cycles reparsing the syntactic blocks that actually execute at runtime, yet I still have no confidence that the syntax of every line in my script is correct, unless I use some external tool like procheck. Way to go, boys! Welcome to 1986!

3. The backtraces. Oh my god, the backtraces. Python has backtraces, and yet somehow they're useful. No one has ever, in the entire history of Tcl, fixed a bug based on its unreadable and baroque backtraces.

4. A special case of item 3: if you're taking the trouble to tell me what line offset in a given function the bug you encountered was, maybe you could spend another thirty bytes or so and mention, casually, what file the error was in? No, that would make too much goddamn sense.

5. Idiomatically, the existence of exceptions in the language is used to excuse lousy programming. Here's how every Tcl program in the world that has ever been written since the beginning of time handles exceptions:

try { set somevar [10000_lines_of_code [1000_lines {$arg}]] } catch { error "Something went wrong!" }

6. Tcl wants to use { and } in places where God intended us to use ( and ).

7. The "expr" construct is hateful. Which of these makes more sense?
value = value ^ 2
set value [expr $value ^ 2]"?

8. You have to explicitly invoke expr, except it's automatic in if and while conditions, which is pretty much the one place where you don't want it.

9. No real data structures to speak of. Everything is a string.

10. Tcl doesn't actually have scoping "rules." Really, they're more like scoping "polite suggestions." You can examine and change (!) variables in your caller's stack frame (upvar). You can execute blocks of code in your caller's context (uplevel). You can tear your own face off with your toenails and devour it, ending your life as a slavering, pathetic beast, whimpering in a pool of your own blood.

In summary: I really, really, really don't like Tcl. Thank you, and good night.

Posted by peterb at October 20, 2004 09:51 PM | Bookmark This

9. No real data structures to speak of. Everything is a string.

Pick Basic (the programming language for Pick-style databases) does a very nifty string-as-data-structure trick.

X = "A;B;C"
CRT X<2>

This turns the semi-colons in the string into Field Marks (@FM), then uses the field extract operator ("<>") to pull out a specific field. It's even more elegant

It also does a very neat integer-as-string trick too:

FOR X = 1 TO 1000
IF X[2] = "00" THEN
CRT "*":

Here I'm using X as an integer in my FOR loop, then later on I'm using it as a string by using the substring operator ("[]"). This prints a * when the last two characters of X are "00", which is on every 100th pass through the loop.

Plus it has other features, such as compiling (to bytecode, no less), printing out exactly where an error happened (but no backtrace), and a few others.

And it dates back to sometime in the late 60s, IIRC. It has evolved in the meantime, of course, so things like bytecode might have come later.

-- Dave

Posted by Dave at October 20, 2004 10:54 PM

Argh. Forgot to delete "It's even more elegant" while editing.

-- Dave

Posted by Dave at October 20, 2004 10:57 PM

Now now, be fair. It was only... hmmm... 12 years ago when I was upgraded to a DECstation 2100.

Oh my god.


Posted by Jonathan Hardwick at October 21, 2004 01:30 AM

I have to take exception with item 1. Remember, everything is a string
(see item 9) and that includes program statements. That's the reason
why you use dollar signs in some places and not in others.

Tcl syntax is, in fact, very consistent. It's just that consistency is
overrated. You know what they say about a foolish consistency.... What
you're actually saying is that Tcl doesn't match the way you like to
think about variables and program statements. That's as good a reason
as any not to like Tcl.

Posted by Ralph W. at October 25, 2004 09:34 PM

Disclaimer first: I love Tcl. Having gone through Fortran, Pascal, Basic, C, Logo (my previous darling), and others, I discovered Tcl 9 years ago. I'm still looking around for a better language, but haven't found one yet. (Yes, I tried Perl and Python).

But love and hate are emotions. Let's talk facts.

Re 1.: "foo" is just a string (which could be the name of a variable. "$foo" is the value of the variable foo, as long known from shells. The difference between a name and a value ($) gets clearly distinguished. (In Lisp you'd need "special forms" to avoid evaluating everything...)

Re 2.: Loop and if bodies, as well as procedures, are compiled to bytecode at first use (since Tcl 8.0). On later calls, only the bytecode is executed again.

Re 3.: I'm often fixing bugs with a quick glance at the backtrace. They look clearer to me than Python's.

Re 7.: [expr] was introduced as a compromise so expressions could be written in infix notation ($a + 1). It is easy to add prefix notation that's more in the Lisp/Tcl spirit, so one can write [+ $a 1] if one wishes.

Re 8.: Conditions in [if], [while] and [for] are expressions, so it's a good move to give them an implicit [expr].

Re 9.: Every value has a string representation, and possibly one of another type, in parallel. Powerful data structures include lists (that can be nested to make matrices or trees), hash tables and dictionaries.

In short: Tcl combines concepts from Lisp, C, and shells. And often it can be even more powerful than any of these.

Posted by Richard Suchenwirth at January 20, 2005 01:14 PM

>In short: Tcl combines concepts from Lisp, C, and shells.

Yes, the worst ones.

Posted by Mike at March 12, 2006 08:53 PM

Please help support Tea Leaves by visiting our sponsors.

November October September August July June May April March February January

December November October September August July June May April March February January

December November October September August July June May April March February January