Updated 2014-09-08 09:07:43 by PeterLewerin

A lot of effort is often put into making things backwards compatible, i.e. making sure that a change in a new Tcl release does not break old code.

This page is about the opposite: writing extra code so new functionality can be used in older versions (of Tcl and Tk, in this context).

An example of this is glob forwards compatibility. The code on that page is about the new glob -dir path * idiom which was introduced in Tcl 8.3. A useful change, and there are so many more like it. The trouble is, once you start using it in your own scripts, you cut off the ability to use those scripts in pre-8.3 Tcl.

One way to get around this is to use conditional code, of the form "if I'm running under Tcl 8.3 or later, do <this>, else do <that>". But that may well defeat the purpose: imagine doing this to use the new "array unset" that way: it might well end up more confusing than a simple info/array condition + action.

That's where forward compatibility comes in: at the start of your app, check what version of Tcl is running, then load a bunch of extra definitions and overrides, which emulate the new features in scripts which call the available (lesser) features.

Forward compatibility is Important. Forward compatibility is Good.

There are plenty of little features which can simplify scripts just a tad more (unset without complaining, file attr changes, glob, info, not to mention Tk changes), but which I have to avoid simply because the consequence of using would have the major implication of forcing a new revision (and compile/configuration hell) onto the people using my code. That is often not justifiable: You want me to fetch Tcl/Tk N+1, figure out the build again, install it again, and introduce the potential of version conflicts or at least dependencies, just so you can use "array unset"? Yah, right..

The irony of writing lots of extra snippets of code to implement forward compatibility is that - in the end - it promotes the adoption of newer versions of Tcl/Tk and new features.

So here's a suggestion: the next time you write an "if Tcl version < N" in your code, how about writing a forward-compatibility snippet instead, and submitting it on this wiki? Just a thought... --jcw

The OOMMF project has done a lot of this. Examples below. DGP

See also Changes in Tcl/Tk for a source of things which can be done.

Here's a start:

Note that most of the above could be improved by using a utility procedure for wrapping commands.

Seems to me that these are good candidates for Tcllib!

Note this can be done in Tcl's C code too:


Are there other list functions which need a forward compatibility wrapper?

KMG 04-Sep-05 Added lindex to the list above for the new multiple-index feature in 8.4.