Exception style (was: Tcl/Tk 8.5a4 released)
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

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

From: Cameron Laird <claird@lairds.us>
Date: Fri Apr 28 2006 - 22:07:53 CEST

In article <4bf4ouF11e870U1@news.dfncis.de>,
Michael Schlenker <schlenk@uni-oldenburg.de> 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.

'Nother perspective: not only does catching exceptions out of,
let's say,

    open $some_file

embody a certain style, but it reduces race conditions to which

    if [file exists $some_file] {
        # Perhaps other tests ...
        set fp [open $some_file]
    } else {
        ....

is subject.

So: I'm uncertain whether your "info exists ..." is truly safer.
Received on Sun Apr 30 03:31:04 2006