October 9th, 2024

Tcl the Misunderstood (Antirez)

Tcl is a misunderstood programming language offering significant flexibility and expressiveness, treating everything as a command, supporting dynamic typing, and providing powerful macro-like capabilities through eval and uplevel commands.

Read original articleLink Icon
AppreciationConfusionFrustration
Tcl the Misunderstood (Antirez)

Tcl, often dismissed as a toy language, is presented as a powerful and misunderstood programming language. The author, Salvatore Sanfilippo, argues that many misconceptions about Tcl stem from its lack of strong leadership after its creator, John Ousterhout, departed. Despite its limitations, Tcl offers significant programming freedom and expressiveness. The language is built around commands, with everything treated as a command, including control structures like if and while. Tcl's dynamic nature allows for late binding, where types are not strictly enforced, enabling flexibility in programming. The language supports lists as a central structure, and mathematical operations can be performed using the expr command. Procedures can be defined to extend functionality, allowing users to redefine built-in commands. The eval and uplevel commands enable powerful macro-like capabilities, allowing for code evaluation in different contexts. Overall, Tcl's design promotes a unique approach to programming that, while sometimes criticized, offers a robust framework for developers willing to explore its capabilities.

- Tcl is often misunderstood and dismissed as a toy language.

- The language allows for significant programming flexibility and expressiveness.

- Tcl treats everything as a command, including control structures.

- It supports dynamic typing and late binding, enhancing its versatility.

- Tcl provides powerful macro-like capabilities through eval and uplevel commands.

AI: What people are saying
The comments reflect a mix of appreciation and criticism for Tcl, highlighting its strengths and weaknesses.
  • Many users appreciate Tcl's extensibility and clean code, particularly in relation to integrating native code.
  • Some users express frustration with Tcl's syntax and its confusion stemming from C-like conventions.
  • There is a desire for modernization in Tcl, including features like closures and better GUI development tools.
  • Users recognize Tcl's power in scripting and configuration, especially in tools like Expect.
  • Some comments highlight Tcl's unique characteristics, such as its regex engine and its use in projects like SQLite.
Link Icon 18 comments
By @foobarian - 7 months
Another excellent aspect of Tcl I found is extensibility of JO's C implementation. At some point I needed to write some native code for speed and making this visible to the Tcl interpreter was a pleasure. Plus the codebase is so clean and well written.
By @js2 - 7 months
Previous discussions:

31 points|pmarin|16 years ago|17 comments

https://news.ycombinator.com/item?id=389107

181 points|zeitg3ist|12 years ago|110 comments

https://news.ycombinator.com/item?id=4920831

131 points|throwaway344|11 years ago|45 comments

https://news.ycombinator.com/item?id=7069642

182 points|goranmoomin|2 years ago|79 comments

https://news.ycombinator.com/item?id=31129936

By @bsder - 7 months
The biggest problem with Tcl is the fact that C won.

This means that "" and {} are expected to work a certain way from C and when you hit Tcl you are HORRIBLY confused.

It's especially confusing as {} is simply quoting and has nothing to do with scope. The fact that Tcl is written such that {} is used with indentation in if-statements muddies the issue even further.

I suspect that a choice of ` (backtick) for Tcl " and " instead of Tcl {} would have made Tcl way less confusing to the vast majority of programmers.

I understand why things weren't done that way--having the ability to know that your quote has different characters for open vs close is very valuable for efficient parsing.

Nevertheless, the Tcl choices were unfortunate given the way history played out.

By @ilrwbwrkhv - 7 months
This is fascinating. I have emailed Tcl's "father" (John Ousterhout) at length and he is one of the few to have actually tried to test what coding patterns make for better code and is the only book I recommend anyone when they want to get better.

Unfortunately most fall for the more popular Clean Code and it's derivatives.

Edit: The book is "A Philosophy of Software Design"

By @lilyball - 7 months
I've long wished to have the free time to write a Tcl-derived language, because it really is so elegant in many ways, it just needs a bit of modernization in some areas. It's been years since I really thought much about this but I recall one of the things it's missing is closures (it does have lambdas at least).

Reading through this article, the memoize implementation does have an issue which is if the memoized command wants to call uplevel or upvar it'll get the wrong stack frame. If I were writing this I'd structure it so it's used like

  proc myMemoizingProcedure { ... } {
    memoize {
      ... the rest of the code ...
    }
  }
such that it can just `uplevel` the code. Or better yet I'd make `memoize` replace the `proc` keyword (or perhaps `memoize proc myMemoizingProcedure …`).

EDIT: I suppose memoizing makes no sense in a procedure that wants to use upvar or uplevel though, because memoizing only works for pure functions.

By @andrelaszlo - 7 months
A lot of the power of expect seems to come from the fact that it's (normally) configured/scripted in Tcl

https://linux.die.net/man/1/expect

I really like that it, like the article mentions, just looks like config for basic scripts but also scales to whatever you need it to do.

By @sshine - 7 months
My favorite obscure line of TCL:

https://github.com/athas/EggsML/blob/master/concieggs/hooks/...

A line that contains a regex pattern for matching regex patterns.

TCL was chosen here because its regex engine isn't too powerful.

By @generalizations - 7 months
The biggest weakness IMHO is the inability to comment out elements of an array. Even bash lets you do this and it makes testing and dev so much easier. Really wanted to love it, but that got in the way too many times.
By @magicalhippo - 7 months
Wish I had this page when messing around with Eggdrop[1] back in the late 90s.

As a self-taught novice programmer that started with QBasic and had moved on to Turbo Pascal, I found Tcl to be very confusing and it left a rather negative impression.

Reading this page now though, it seems a lot more logical and reasonable than it appeared at the time.

[1]: https://docs.eggheads.org/tutorials/firstscript.html

By @WillAdams - 7 months
One thing which I've always not understood about Tcl/TK is why there isn't a standard graphical tool for laying out a GUI program.

For a long while, when I might have used Tcl/TK, I instead used Runtime Revolution/Livecode (a cross-platform HyperCard clone) which had a very nice system for interactively drawing programs.

I'd really like for there to be an agreed-upon standard option for graphical program development which was interactive and cross-platform.

By @import_awesome - 7 months
Another great feature of Tcl for writing servers it that you can reload the code while it is running and keep all the state and connections open. Code up/bootstrap your server while it is running the whole time. Sure this is a security nightmare, but it is fun to code.
By @leoh - 7 months
Fun fact: SQLite’s test suite is written in TCL https://github.com/sqlite/sqlite/blob/master/test/strict1.te...
By @allknowingfrog - 7 months
Does anyone know of a good tutorial for getting starting with Tcl/Tk that still makes sense in 2024? I'm really intrigued by the idea of building and shipping simple, cross-platform GUIs, but I'm completely overwhelmed by all of the installation and configuration options. It seems like tclkit is supposed to be the go-tool tool for self-contained executables, but I honestly can't even figure out which site is the source-of-truth for downloading it, let alone installing it.
By @mseepgood - 7 months
This language seems like a security nightmare to me regarding code injection attacks through untrusted inputs.
By @zombot - 7 months
> Concept 9: Eval and Uplevel

That's where it gets really criminal: Dynamic scoping rules. There is no lexical scoping and hence no closures. If you use `uplevel`, your procedure works or doesn't, depending on the caller. There is a reason Tcl is the last language that uses this braindead mechanism.

By @77pt77 - 7 months
Tcl is basically a sloppier Perl with a GUI.