Re: Exception style (was: Tcl/Tk 8.5a4 released)



On Fri, 28 Apr 2006 22:07:53 +0200, Cameron Laird <claird@xxxxxxxxx> wrote:

In article <4bf4ouF11e870U1@xxxxxxxxxxxxxx>,
Michael Schlenker <schlenk@xxxxxxxxxxxxxxxx> wrote:
.
[little sympathy for cer-
tain legacy maintainers]
.
.
One reason to really check what you want to know and not some side
effects of another command. [info exists BOB($x)] would be safer.
.
.
.
There's a real question here whose answer I certainly don't know.
For decades, I, too, have not only said, "well, you can check what
you *really* want ...", but have advocated doing so as the clearer
solution. On alternate days, though, I'm sympathetic with the
argument that what one really wants in this situation is to
increment the variable, and that anything else *deserves* to be
coded as an exception.

I agree. One other condition is where someone accidentally mistypes a variable. Currently he/she would get an error and would realize his/her mistake.

The new non-error solution is error prone, because someone may not realize that this variable does not exist or is incorrectly referenced - and I can imagine [upvar]/[uplevel] related situations where this may not be easily traceable.

So: I'm uncertain whether your "info exists ..." is truly safer.

I agree. Although Tcl itself is singlethreaded in context of each variable, I can imagine variables being linked to an SQL database, where [info exists] may execute some SQL and [incr] will definitely execute read traces and write traces. Sure, it is a complex scenario, but tcldb's config does that and I personally use it quite often for counters.

I am for having a -nocomplain (or any other name) switch :)

--
WK
.