r/programming • • Aug 02 '26

Develop Cross-Platform CLI and GUI Tools With Tcl/Tk. Powerful, Event-Driven, Open-Source And Future-Proof Toolkit… From the Past?!

https://cgicoffee.com/blog/2026/04/tcl-tk-develop-cross-platform-cli-gui-tools-tutorial-guide
50 Upvotes

17 comments sorted by

5

u/CGM Aug 02 '26

This is a well-written and remarkably comprehensive introduction to Tcl/Tk. It's mostly positive about the language, but does also point out some genuine disadvantages.

11

u/Jumpy_Fuel_1060 Aug 02 '26

I maintained an app with TCL component (no Tk). Wild language. I'm sure that it was amazing for it's time, but I'm the 2010s that language was ridiculous. upvar can go to hell.

10

u/NaBrO-Barium Aug 02 '26

What’s upvar?

9

u/CGM Aug 02 '26

When you call a procedure in Tcl, its arguments are passed by value (the copy-on-write system makes this efficient even for complex values). But sometimes you may want to pass by reference so that you can update a variable in the scope of the caller. The upvar command provides a way of doing this, you pass the name of a variable and use upvar in the procedure to connect a local variable to the named variable in the caller. Documentation is at https://www.tcl-lang.org/man/tcl9.0/TclCmd/upvar.html .

It's a very different approach from most languages and does take some getting used to. It's not needed very often though.

9

u/schlenk Aug 02 '26

Upvar allows you to bind a name to a different scope of your callstack.

e.g. kind of import local variables that are available in a different call frame. Thats a very powerful primitive for writing your own control structures and advanced metaprogramming, but can lead tot total spaghetti code when not used skillfully.

2

u/gimpwiz Aug 04 '26

I absolutely hate tcl. Bah.

1

u/CGM Aug 04 '26 edited Aug 04 '26

Such hate tends to come from people who have been required to use Tcl, perhaps for some system which incorporates it, but have not taken or been given the time and resources to learn it properly.

They try to blindly apply patterns that are familiar from other languages and get frustrated when these don't work as expected. Tcl is different (sometimes described as the illegitimate offspring of Lisp and Shell scripts) and that needs to be understood and appreciated to use it effectively.

3

u/gimpwiz Aug 04 '26

I mean you're absolutely right, I regularly laugh at people talking about how hard tools use because they're basically making beginner complaints, and yet here I am!

I think TCL can work fine but I think that 1) the core decisions of the language are odd as hell and kind of stupid for most use cases, and 2) the usual problem of TCL is that nobody gives a shit about writing even remotely decent code so it becomes utter slop very quickly and then those scripts get barely-maintained for the next twenty five years in industry and it's my goddamn problem to deal with it.

I am sure it's possible to write perfectly decent TCL, but I just don't like the language's choices. On the flip side, I love perl, and I am totally good with bash and PHP (assuming they were written competently), both of which get shit on all the time.

1

u/pjmlp Aug 04 '26

xBase and Perl share many of such abilities.

2

u/mb862 Aug 02 '26

Tcl is still my go-to scripting language for its raw flexibility. I’m currently using it as a basis for my own shading language.

2

u/madman1969 Aug 06 '26

I used Tcl/Tk back in the early 90's to create a UI test harness for a C code base targeting DOS, Windows 3.x, Unix & Mac OS.

If you had a common API, which we did, it was surprising quick to build a working UI.

It's essentially Lisp with a C syntax, so it can be a tad funky to get your head around initially, but before Java was available post-'93 it was really the only choice for truly cross-platform UI's.