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.
I've not seen the code, but the author has written a book [1] which has the advice I've ever seen. Much better than "Clean code" and other books in that direction. So it does not surprise me that the code is so well written.
I'm pretty sure Ousterhout intended for people to write a few deep modules in C and only use Tcl to glue everything together/provide extensibility.
(we did exactly this for networking code about 30 years ago: C for the data plane and Tcl for the control plane. That architecture remained in service for decades.)
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.
The use of {} for strings without substitutions and effectively for scope are actually interrelated, remarkably.
Scopes are special syntactic forms that delegate variable substitution to the associated procedures. For example, a "for" statement evaluates the body of the function after substituting the loop variable. In a string based language, that's basically the same as expressing the scope in a string form where the string content is passed verbatim as an argument without variable substitution or function invocation.
Having used Tcl extensively back in the day, I am not sure that this syntactic cleverness really was a major impediment to adoption. It was just something to learn. Same was true with [] meaning lisp-like function calling rather than array definition.
Baseline Tcl's biggest challenge, in my opinion, was providing mechanisms to write modular code for larger programs and data encapsulation. Core Tcl put off decisions about the appropriate mechanisms to do so by only providing "namespaces" as a building block for higher level third-party syntax. That led to fragmentation at a time when other languages were gaining popularity.
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"
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.
In our application server written in Tcl/C, the configuration files were a Tcl DSL, the server would search for specific extensions and source the files, done.
>TCL was chosen here because its regex engine isn't too powerful.
Uh, not sure I see the significance but wouldn't that make Tcl less apt for this than something else? Why would you purposely choose a less powerful regex engine?
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.
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.
Don't blame you. If you treat tcl as a c-like scripting language, it's a mess. If you treat it as a "shell & lisp" combo, then you get to see it's power & flexibility.
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.
I don't think it is needed. I am a hobby programmer and not even remotely competent but I can whip up GUIs in Tk with little effort and I find it quicker and easier than the graphical UI designers.
Once upon a time (Tcl??/Tk3.6) there was XF by Sven Delmas. It had some issues and really would have needed something like namespaces. AFAIR it took forever to get a stable version for Tk4.0.
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.
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.
I recommend https://wiki.tcl-lang.org/page/LUCK as a very easy way to build self-contained executables which bundle Tcl, a large choice of extensions, and your own code.
John Ousterhout's Tcl and the Tk Toolkit is great and has been updated to Tcl/Tk 8.5 which is recent enough to not cause headaches. Don't think it goes into self contained executable but covers everything else very well.
Edit: Just remembered that Tcl/Tk: A Developer's Guide by Flynt has a chapter on self contained executables and the various tools for making them. Have not looked into this book much so can't comment on it.
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.
I came into this comment thread thinking "why should I bother with Tcl if I know Perl" but your comment nearly sold me. When I do Perl it's because I can afford to be sloppy, and coming with a GUI sounds like a good deal!
TCL fits on microcontrollers. If I'm looking at anything other than Python or bash(for trivial logicless scripting) it's probably because I'm in a constrained environment.
That’s a hot take for one language with basically a sheet to describe it[0], and another whose “rules” are best described by “whatever this implementation does.”
[+] [-] foobarian|1 year ago|reply
[+] [-] f1shy|1 year ago|reply
[1] https://milkov.tech/assets/psd.pdf
[+] [-] davidw|1 year ago|reply
I got to write some of the updates in this 2nd edition regarding the C interface:
https://www.oreilly.com/library/view/tcl-and-the/97803216017...
[+] [-] 082349872349872|1 year ago|reply
(we did exactly this for networking code about 30 years ago: C for the data plane and Tcl for the control plane. That architecture remained in service for decades.)
[+] [-] johnisgood|1 year ago|reply
[+] [-] js2|1 year ago|reply
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
[+] [-] bsder|1 year ago|reply
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.
[+] [-] mhalle|1 year ago|reply
Scopes are special syntactic forms that delegate variable substitution to the associated procedures. For example, a "for" statement evaluates the body of the function after substituting the loop variable. In a string based language, that's basically the same as expressing the scope in a string form where the string content is passed verbatim as an argument without variable substitution or function invocation.
Having used Tcl extensively back in the day, I am not sure that this syntactic cleverness really was a major impediment to adoption. It was just something to learn. Same was true with [] meaning lisp-like function calling rather than array definition.
Baseline Tcl's biggest challenge, in my opinion, was providing mechanisms to write modular code for larger programs and data encapsulation. Core Tcl put off decisions about the appropriate mechanisms to do so by only providing "namespaces" as a building block for higher level third-party syntax. That led to fragmentation at a time when other languages were gaining popularity.
[+] [-] boomlinde|1 year ago|reply
[+] [-] lilyball|1 year ago|reply
[+] [-] ilrwbwrkhv|1 year ago|reply
Unfortunately most fall for the more popular Clean Code and it's derivatives.
Edit: The book is "A Philosophy of Software Design"
[+] [-] lilyball|1 year ago|reply
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
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.
[+] [-] monetus|1 year ago|reply
https://wiki.tcl-lang.org/page/Closures
https://wiki.tcl-lang.org/page/Emulating+closures+in+Tcl
TCL 9 has surely fiddled with tcl_ObjType I hope, but it doesn't seem like it from a glance.
[+] [-] andrelaszlo|1 year ago|reply
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.
[+] [-] pjmlp|1 year ago|reply
[+] [-] AceJohnny2|1 year ago|reply
[+] [-] sshine|1 year ago|reply
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.
[+] [-] stackghost|1 year ago|reply
Uh, not sure I see the significance but wouldn't that make Tcl less apt for this than something else? Why would you purposely choose a less powerful regex engine?
[+] [-] generalizations|1 year ago|reply
[+] [-] lilyball|1 year ago|reply
[+] [-] cmacleod4|1 year ago|reply
[+] [-] magicalhippo|1 year ago|reply
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
[+] [-] isr|1 year ago|reply
[+] [-] WillAdams|1 year ago|reply
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.
[+] [-] ofalkaed|1 year ago|reply
[+] [-] musicale|1 year ago|reply
It is a bit surprising since it seems like you could use Tcl/Tk to write it.
The Tk canvas makes writing simple drawing programs fairly easy, and a GUI editor seems like it wouldn't be terribly difficult.
[+] [-] rmu09|1 year ago|reply
[+] [-] musicale|1 year ago|reply
I wish there were more of these, preferably open source (and, since I'm dreaming, native and web versions.) ;-)
[+] [-] import_awesome|1 year ago|reply
[+] [-] rwmj|1 year ago|reply
[+] [-] leoh|1 year ago|reply
[+] [-] graemep|1 year ago|reply
[+] [-] allknowingfrog|1 year ago|reply
[+] [-] cmacleod4|1 year ago|reply
There is a tutorial on the Tcl wiki which should be reasonably up-to-date - https://wiki.tcl-lang.org/page/Tcl+Tutorial+Lesson+0 .
[+] [-] ofalkaed|1 year ago|reply
Edit: Just remembered that Tcl/Tk: A Developer's Guide by Flynt has a chapter on self contained executables and the various tools for making them. Have not looked into this book much so can't comment on it.
[+] [-] mseepgood|1 year ago|reply
[+] [-] zombot|1 year ago|reply
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.
[+] [-] 77pt77|1 year ago|reply
[+] [-] BoingBoomTschak|1 year ago|reply
[+] [-] kqr|1 year ago|reply
[+] [-] tlavoie|1 year ago|reply
[+] [-] eternityforest|1 year ago|reply
[+] [-] bch|1 year ago|reply
That’s a hot take for one language with basically a sheet to describe it[0], and another whose “rules” are best described by “whatever this implementation does.”
[0] https://wiki.tcl-lang.org/page/Dodekalogue
[+] [-] unknown|1 year ago|reply
[deleted]
[+] [-] unknown|1 year ago|reply
[deleted]