Comparing Tcl with PHP

lv wrote: Would someone consider detailing some of the conceptual differences between PHP and Tcl? What kinds of things will a PHP programmer find confusing or at least different, when learning Tcl?


schlenk My take at the subject:

Documentation

For PHP there is a vast amount of documentation in various languages available, while the Tcl documentation is less centralized and large. A newcomer from PHP will probably miss the sheer amount of documentation, but he will be very happy to see that the Tcl docs are much more complete (they mostly tell you what a command is doing, instead of giving just examples or telling you "this function is not yet documented, there is just the argument list available").

Packages and Extensions

The PHP core distribution comes with tons of additional modules compiled. Lots of useful functionality. A PHP to Tcl convert will surely be surprised how naked a Tcl core looks until he discovers the Tcllib and the amount of packages available for Tcl in various places. Tcl has no central repository like PEAR or the huge libs included with php. But if a newcomer compares the PHP offerings with the Tcl ones he will see a lot of differences: The Tcl packages mostly have a better API, not a C API wrapped without much thought as in many of the PHP libs. The names are more consistent, more logical its not such a wild mix of naming conventions (although there are some oddities like the destory, delete, rename confusions.)

Data structures

A PHP coder will see Tcls arrays and try to use them like the PHP arrays and fail miserably. PHP arrays are a bizarre mixture of hashtable and list, very powerful but confusing at times.

Quoting

In PHP you have to quote all the time, to denote literal strings. A PHP coder may be troubled by the distinction between braces, brackets and quotation marks and their effect on substitution. Typical traps are misplaced or missing spaces and newlines, use of the wrong type of braces (round instead of curly braces in commands like for, while, and if ).

Use of variable names

All variablenames in PHP start with a $ so a PHP user trying to use Tcl will use way too many $'s in his Tcl code and will not understand what's wrong at first. Interestingly in the PHP extension Smarty [L1 ] (for website templates) the use of $ for variable names is quite similar to Tcl.

NOTE: Smarty is not an php extension, rather a class written in php. The "language" smarty uses for it's template engine can not in any way be compared with the scripting language PHP.

Lots of other stuff

Tcl's powerful introspection and interp commands, the ability to define your own control structures. Tcl's lack of references and standard OO system. Tcl's good unicode handling.


If that is any encouragement to people coming from PHP, LES used to be a big fan of PHP, had quite some trouble getting to think the Tcl way, but after a couple of years he never thinks of going back. He says: "I can no longer remember the last time I wrote a single line of PHP. PHP is like a young, physically strong and unwise ninja, but Tcl is just Zen. I only wish Tcl didn't have the inconsistency in names that PHP also has, although it is a lot worse in PHP. I even think that some command naming convention should be added as the thirteenth rule [L2 ], [L3 ]."