Version 6 of proc or interp alias

Updated 2004-03-01 07:43:43

Which of these is better and why?

    button .b
    rename .b .b:cmd
    proc .b { args } "eval [list WidgetHandler .b] \$args"

or

    button .b
    rename .b .b:cmd
    interp alias {} .b {} WidgetHandler .b

MS prefers the second, for both clarity and performance reasons (no string parsing at run time).

PWQ An alternate for the first would be:

        proc .b {args} {uplevel 1 WidgetHandler .b $args}

So that the widget handler has access to the callers namespace et al.

Vince does anyone have performance data on the different approaches? Note that the proc should be:

        proc .b {args} {uplevel 1 [list WidgetHandler .b] $args}

for optimal performance, I think (but haven't tested!).

RS Widget handlers in UIs probably don't make a difference if they run a few milliseconds longer. I'd go for the version that is easiest to read. Oh, and the list grouping for uplevel is not necessary, as both list elements obviously have no whitespace in them...