8 ms·
Tcl the Misunderstood (2006)
- spijdar 5y ago> Every string is internally encoded in utf-8, all the string operations are Unicode-safe This seems very slightly disingenuous, if my memory is correct. I don't remember all the details, but I ran into an issue with a Tcl application a while back and Unicode support. Digging into it, I recall that the Tcl interpreter actually represents every character as a predefined number of bytes, set by a preprocessor definition. The default was 2, and cut off any Unicode character that needed more than 2 bytes to encode, unless you were willing to recompile the interpreter to use 4 bytes, at the cost of doubling memory consumption for every string. Very nitpicky, but I think it's important to point out it's not "quite" utf-8, because Tcl needs each codepoint to be O(1) indexable in an array, something normal utf-8 can't do.
- masklinn 5y ago> Digging into it, I recall that the Tcl interpreter actually represents every character as a predefined number of bytes, set by a preprocessor definition. Ah, that’s exactly what old python did. Wonder of it was inspired by the tcl solution. Fwiw because they rejected indexing recent cpython uses a variable encoding based on contents (possibilities are iso-8859-1, ucs2, or ucs4). That does mean adding an astral codepoint to an ASCII string quadruples its size. Pypy, on the other hand, uses utf-8.
- bawolff 5y agoThat's pretty much what every older language did. I assume its because the original unicode only supported 2 byte characters, and even after astral characters became a thing it took a while for them to be used for non-cjk things.
- masklinn 5y ago> That's pretty much what every older language did. The fixed size, but I’m referring to the compile-time width switch. I may be wrong but I was under the impression most older langages simply remained on their original character width (or left the issue ill defined and/or added an ancillary type like C).
- slbtty 5y agoThe author of this article is the creator of Redis.
- forgotpwd16 5y agoWhich Redis started out as a relatively short (~300 lines) Tcl program.
- repiret 5y agoWhat I like most about TCL is that a TCL REPL feels a lot more like a normal command prompt than Lua or Python or whatever. If I’m going to write a complex program, TCL wouldn’t be my first choice, but if a program I’m using has a command prompt (think autocad or the debug console a lot of games have). Plenty easy for one-off commands, but with a simple and powerful programming language there if you ever need it. Put differently: The command line ergonomics of POSIX shell, with the scripting ergonomics of Lisp
- auxym 5y agoYeah, that may be why it became popular in CAE/EDA tools, one of the the few places it remains used these days. IMO Tcl works well for that use case, but it often catches shit from people who've had to use it. I think it's either because they misunderstand the language (as in the article, but also not that people who use CAE or EDA tools may have very little programming background) or that the vendor APIs provided to interact with the tool are very poorly designed (which I have definitely experienced).
- Normille 5y ago
- Shared404 5y ago> On-Topic: Anything that good hackers would find interesting. That includes more than hacking and startups. If you had to reduce it to a sentence, the answer might be: anything that gratifies one's intellectual curiosity. From the HN Guidelines. Note the lack of the pattern "new" anywhere in there.
- Normille 5y ago>Note the lack of the pattern "new" anywhere in there. Er... it's literally the name of the site, 'Hacker NEWS'. A 16 year old article is not news. No matter how interesting it might be. The custom here is to put the year in brackets after the title, when posting an old article
- Shared404 5y agoNonetheless, the guidelines allow for such things - and I'm grateful they do, as I enjoyed the time I spent reading this article and am smarter now than I was beforehand. I do agree that it should've originally had the year added when originally posted.
- porker 5y agoHN gets numerous articles submitted multiple times, as people discover them for the first time. It's frowned upon to repost too frequently but this was last posted to HN on Oct 28, 2019 so I see no problem with it.
- layer8 5y agoEverything old is news to some significant part of the audience.
- bitwize 5y agoThe idea that Tcl was a toy came from the 90s and the Tcl Wars Stallman was involved with. But to Stallman, anything other than Lisp is pretty much a toy. Tcl is indeed a deep, deep rabbithole -- again, deeper than our dimension allows and lined with toothed cilia... but I can totally see where a person might look in Tcl's deadlights and want to be there.
- jrapdx3 5y agoIronically Tcl is very Lisp-like in certain respects, though also quite different. Rabbitholes notwithstanding Tcl can be enormously useful and productive. In particular I think the built-in Tcl object-oriented features are a real asset and not nearly the same sort of rabbithole as you encountered in the past.
- bitwize 5y agoIt does have very flexible metaprogramming capability and the syntax of the language can be extended in the language itself, very much like Lisp, and like Lisp it has a high skill ceiling and a huge possibility space to explore. It's the ways in which it is not like Lisp, the features that Lisp hackers discovered decades ago were nests of bugs and confusion that... arghhh. My overall impression of Tcl, however, is quite positive -- and Tcl/Tk is a JATO bottle for rapid GUI development that no Lisp implementation has yet been able to match -- not without embedding or incorporating Tcl itself (e.g., PS/Tk: https://wiki.tcl-lang.org/page/PS%2FTk https://wiki.tcl-lang.org/page/PS%2FTk).
- sirfz 5y agoTCL was my entry into coding back when I was a teenager, haven't touched it in over 12 years or so but I'll always fondly remember it. The title of this post is very familiar to me, I'm sure I read it back when it was published but its cool to now know it was written by the creator of redis which I now use extensively
- jrapdx3 5y agoI think it's worth pointing out that in the years since this article was written (2006) quite a few new features have been added to Tcl. A few of the more significant include coroutines, robust object-oriented system, tailcalls, apply (lambdas), namespace ensembles, et.al. Of course some of these features were already present in other languages. However, steady improvements to Tcl have pushed the language well beyond how it was described in the article. Definitely not a "toy" but overall as capable as the other scripting tools out there.
- pjmlp 5y agoTCL already had a couple of well known packages for OOP before 2006, like [incr Tcl].
- thanatos519 5y agoMy favourite thing about Tcl is (was? This was 25 years ago) that adding commands just requires a couple of Tcl things, then an argc/argv, so it was relatively simple to turn an existing C program into a Tcl command: int my_command (ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[]) { ... } However, that might have been the only thing I liked about Tcl. For some binary data import tasks I ended up writing a Perl program that translated it into Tcl.
- oblio 5y agoBinary data import was probably the antithesis to Tcl's "everything is a string".
- Areading314 5y ago
- xarope 5y agoI remember bumping into Tcl as part of Tcl/Tk, during my xwindows days. Never realised there was still so much work ongoing for the language! Reminds me of Forth too... do people still make firmware with Forth?
- uwagar 5y agoexpr is horrible though. but i love tcl.
- yesenadam 5y agoIt's easy to alias expr to =, which enhances write- and readability : % interp alias {} = {} expr = % set x [= 2 + 3] 5 Also aliasing lindex to @ is nice % interp alias {} @ {} lindex % set a {1 2 3} 1 2 3 % @ $a 1 2
- pwg 5y agoAlso, if you set your namespace path like so: namespace path {::tcl::mathop ::tcl::mathfunc} Then you get very LISP like math operators % set x [+ 2 3 [- 5 20]] -10 and math functions % set x [abs -12] 12
- pxeger1 5y agoThis article fails to note that Tcl is very closely related to shell script. A lot of the concepts listed already exist in Shell, and nobody complains that Shell is only a toy language.
- forgotpwd16 5y agoMany complain that shell scripting isn't suitable for anything longer than few lines.
- thesz 5y agoTcl forces you to create new data, because you have to think and work harder to introduce effects on variables in upper scope through the use of uplevel and upvar. This reduces side effects significantly and makes data transformation explicit. Which, in turn, reduces cognitive load and increase productivity. Tcl also does not have distinguished NULL value like Python, C, C++, C# and many other languages. You do not have to account for that. The reduction of side effects and no universal no-value value puts Tcl in my hierarchy of programming languages right below Haskell and above pretty much everything else. Tcl is very easy to use when you know how to structure the program. I still use it for various prototyping when I do not want strict type discipline.
- zelphirkalt 5y agoDoes this non-existence of a no-value not only mean, that when there is no result value, another value (like false or empty string or empty list or whatever) will be used to express that fact, or that an exception is used? One would have to check for those in some cases as well. Those might not be always good alternatives reducing required checks. How does it work?
- auxym 5y agoOne fundamental principle in tcl is that everything is a string (EIAS) [1]. Therefore, an empty string "" is the same thing as a "null value" or 0-length list, but generally doesn't require any special treatment (your function that takes a list as input generally should know how to handle empty lists). [1] In practice things are typed in the interpreter internals for performance reasons, but the language behaves as if EIAS.
- thesz 5y agoLet me offer you an example: proc maybe {onno onjust val} { if {[llength $val] == 2 && [string equal [lindex $val 0] Just]} { lappend onjust [lrange $val 1 end] return [uplevel $onjust] } # I cannot extract value return [uplevel $onno] } maybe {puts "---"} {puts } {Just "huh?"} maybe {puts "---"} {puts } {} This is an example of custom control statement, modeled after Haskell's maybe [1]. [1] https://hackage.haskell.org/package/base-4.16.1.0/docs/Data-Maybe.html#v:maybe https://hackage.haskell.org/package/base-4.16.1.0/docs/Data-... It is easy to use and write. You can follow algebraic data types convention and prefix values with tags and use something like control structure drafted above. I did that, it is relatively comfortable. Note that special case of empty list also handled as if it is Nothing. So it is more useful than would appear. ;)
- deepsun 5y agoWatching someone learns basics of programming in Python, I realized that Python is actually not that easy to learn for beginners as I thought: 1. Types in Python are implicit. It's really hard to explain that they need to always think about what type something is, especially when they haven't grasped the concept of types yet. 2. Indentation as part of the language. I thought it's a great thing for beginners, but it's actually confuses beginners that empty space affects your program, e.g. they think that spaces around assignment or arithmetic operators should affect their program too, which is not the case. 3. Ranges for iteration -- they just memorize the syntax blindly :( So I started to wonder whether Pascal is better to learn for beginners -- you have to list all the types at the beginning, and no implicit conversions are done. But now I think what about TCL? Maybe it'd be even easier for total beginners?
- rscho 5y agoYou could try something with a regular syntax. It doesn't work for everyone, but when it works it works really well. Racket comes to mind, and it has a progressive suite of languages from neophyte to full-blown. In addition to a community focused on pedagogy and CS fundamentals. https://racket.discourse.group/ https://racket.discourse.group/
- layer8 5y agoThe traditional answer was to use a BASIC dialect. Minimal syntax, minimal structure, simple imperative commands. A lot simpler than Pascal. I don’t know TCL very well, but its scope semantics may be confusing. I’d take a look at LOGO also.
- utucuro 5y agoHaving learned Basic (Commodore as well as Qbasic), Pascal (not Delphi) and TCL in my youth, TCL is the only one I used in production. TCL is fairly simple to learn, it only takes a few concepts really, and it is quite a joy, if memory serves right. Of those I mentioned, it is the only one that I would touch again, for any reason, whether for fun or profit.
- buescher 5y ago
- swah 5y agoFond memories of tcl inside ModelSim - it was not the Lua I was enjoying then but, like using emacs, made me love automation and coding a little bit more.
- macintux 5y agoSome discussions over the last several months, including just yesterday: * The Birth of Tcl: https://news.ycombinator.com/item?id=31111220 https://news.ycombinator.com/item?id=31111220 * TclTutor 3: https://news.ycombinator.com/item?id=30327945 https://news.ycombinator.com/item?id=30327945 * Tcl/Tk Spline Editor: https://news.ycombinator.com/item?id=29772621 https://news.ycombinator.com/item?id=29772621 * Tcl library for CSP: https://news.ycombinator.com/item?id=29421786 https://news.ycombinator.com/item?id=29421786 * Why Tcl syntax is so weird: https://news.ycombinator.com/item?id=29143346 https://news.ycombinator.com/item?id=29143346 * Tcl: Lisp for the masses: https://news.ycombinator.com/item?id=28957701 https://news.ycombinator.com/item?id=28957701
- toss1 5y agoYes. I've been kind of wondering about the apparent promotion of Tcl here recently - is someone pushing it for some reason, or is it just a passing fad in a slow (tech) news time?
- macintux 5y agoI think topics tend to cluster as people follow up on interesting posts; at least, that would explain two active discussions in two days.
- 0des 5y agoYears back, for a lot of us, tcl and tk was the bees knees. It was what we use Qt for now, but much easier in some regards. I think sometimes that as we reach peak saturation in other languages people branch back out into areas we enjoyed in the past
- utucuro 5y ago2 decades later, I do not remember what I did with TCL, but I remember that I enjoyed it... This may explain things...
- ufo 5y agoThe thing that I most appreciate about Tcl is that it feels like Unix shell "done right". It is still a bit weird because everything is a string, but it doesn't have all those footguns around variable expansion, such as word splitting. It also has decent support for subroutines and local variables, no weirdness with subshells and so on.
- Dreami 5y agoHas there been an attempt at doing a shell?
- siskiyou 5y agotclsh is included https://tcl.tk/man/tcl8.5/UserCmd/tclsh.htm https://tcl.tk/man/tcl8.5/UserCmd/tclsh.htm If you meant a login shell... https://wiki.tcl-lang.org/page/Is+tclsh+or+wish+suitable+as+a+login+shell https://wiki.tcl-lang.org/page/Is+tclsh+or+wish+suitable+as+...
- IshKebab 5y agoThis is nonsense. I have had the misfortune of having to learn TCL (it's standard in the EDA world unfortunately) and it is most assuredly a toy language. That doesn't mean you can't write big complicated programs with it. You can do that with any language. But stuff like this is an outright lie: > There are no types, and you don't need to perform conversions, however, you aren't likely to introduce bugs because the checks on the format of the strings are very strict. You aren't likely to introduce bugs when literally every type is a string. Even lists. Lists are strings. Lists of strings are strings. Maps are strings. It's pretty insane, and the interpreter does some horrible magic so that if you never access a list as a string it can store it internally as a real list (to avoid insanely bad performance) but to the programmer it's still a string and nothing prevents you from treating it as such. I actually made a semi-funcitonal WASM-to-TCL transpiler to avoid having to write TCL. Worked kind of well! Unfortunately WASM is quite large and I lost interest before completing it.
- dgan 5y agoWow, looks like TCL is "the better bash"
- buescher 5y agoSomeone else posted a great link explaining why you probably don't want tclsh or wish as your login shell. Today zsh or fish is the better bash, really. Here's another dead end unexplored though - dtksh! https://www.brendangregg.com/dtkshdemos.html https://www.brendangregg.com/dtkshdemos.html
- pjmlp 5y agoIt might be powerful, and Lisp like, however in any large application eventually the amount of C code in extensions to make it perform, outgrows the TCL code. And then one stars wondering if it isn't better to migrate to something else.
- zulban 5y agoOverwhelming number of tcl positive comments here. Must be selection bias. Tcl is ridiculous. I propose that anyone who prefers tcl over other top languages in 2022 simply doesn't have productivity or teamwork as their top goal. Do you want your language to help you solve real problems, or do you just enjoy your weird toy from another era? Everything is a string..? Please.
- gilbetron 5y agoI've managed to work on two TCL codebases in my career, one in 1992ish, and one in 2011ish. I was very surprised to be working on it the second time! I've said it before, but working on TCL is interesting, kinda fun, and ultimately a lesson in frustration once you get to a certain sized codebase. It really hammered home the need for static typing as your repo gets over 50k lines because it is so "type free". However, it is a cool thought experiment for it's premise, which is more-or-less, "what if everything is a string". It has a lot of benefits, and a lot of nasty side effects. I'm glad I spent time doing it, and I think the use case for which it was made ("Tool Control" roughly speaking) it has good ideas. TK was fun, as well, I miss it in some ways. But ultimately, TCL is a dead end for a programming language - the negatives accumulate too quickly.