• How to return a value from a proc

    From Cecil Westerhof@21:1/5 to All on Sat May 7 06:52:21 2022
    At the moment I do as last statement of a proc:
    lsort -index 1 -integer -decreasing [lsort -index 0 ${swapList}]

    Is this OK, or is it better to do:
    return [lsort -index 1 -integer -decreasing [lsort -index 0 ${swapList}]]

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alex P@21:1/5 to All on Sat May 7 05:10:06 2022
    As for a performance, both are identical in Tcl 8.6, but as for a style, 'return...' seems to be better.

    The 'return' command makes a code a bit more self-documented, as if saying: look, this procedure can be used in expressions!

    Also, 'return' (as well as 'proc' and 'method') command is highlighted by some editors, so that a code with proc + return is framed with them, which makes the code more viewable.

    At last, if a procedure returns values in several places, its last command must be 'return'. It's an insurance against possible mistakes and a matter of good taste.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alex P@21:1/5 to All on Sat May 7 04:59:35 2022
    As for a performance, both are identical in Tcl 8.6, but as for a style, *return...* seems to be better.

    Also, *return* makes a code a bit more self-documented, as if saying: look, this procedure can be used in expressions.

    And *return* (as well as *proc* and *method*) command is highlighted by some editors, so that a code with *proc* + *return* is framed with them, which make the code more viewable.

    At last, if a procedure returns values in several places, the last command must be *return*. It's an insurance against possible mistakes and a matter of good taste.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Alex P on Sat May 7 15:46:20 2022
    Alex P <[email protected]> writes:

    As for a performance, both are identical in Tcl 8.6, but as for a style, *return...* seems to be better.

    Also, *return* makes a code a bit more self-documented, as if saying:
    look, this procedure can be used in expressions.

    And *return* (as well as *proc* and *method*) command is highlighted by
    some editors, so that a code with *proc* + *return* is framed with them, which make the code more viewable.

    At last, if a procedure returns values in several places, the last
    command must be *return*. It's an insurance against possible mistakes
    and a matter of good taste.

    OK, I will add the return.

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)