Version 7 of Comparing Tcl with PHP

Updated 2005-01-26 13:32:31

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.

* 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.


Category Language