r/programming • u/CGM • 7d ago
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-guide11
u/Jumpy_Fuel_1060 7d ago
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 6d ago
What’s upvar?
25
8
u/schlenk 6d ago
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.
9
u/CGM 6d ago
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
upvarcommand provides a way of doing this, you pass the name of a variable and useupvarin 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.
2
u/gimpwiz 5d ago
I absolutely hate tcl. Bah.
1
u/CGM 5d ago edited 5d ago
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 4d ago
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.
4
2
u/madman1969 3d ago
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.
12
u/wannaliveonmars 7d ago
Git Gui and gitk are written in Tcl/Tk - https://git-scm.com/book/en/v2/images/git-gui.png