This is something of a general question. Assuming TCL 8.6, let's ay that I have a rather short procedure. I have 2 ways of returning the value of interest:
1. use some standard practice if/else code, store in a variable, and return the variable's value. For example:
proc me { gop goo } {
if { [ lomsa $gop ] {
set ret [ foo $goo $gop ]
} else {
set ret [ bar $gop $goo ]
}
return $ret
}
2. use the ternary argument, and basically, have the procedure no added private variable (that is, only the arguments are used). The output of ternary expression is what returns the value. For example:
proc me { gop goo } {
expr { [ lomsa $gop ] ? [ foo $goo $gop ] : [ bar $gop $goo ] }
}
Readability is considered by some members of my team to be better slightly better in item 1.
I can't access the pseudo code engine in my TCL setup (it is a shell from a vendor), but I assume that difference in the code, and its' performance will be, but only slight, if at all. I.e., the procedure needs to store the value returned somewhere. How much is the cost of registering a specific variable for it, vs. just keeping it as a return value?
The question can be extended, for example, for switch statements. Same rules apply. The switch statement can store in a variable, and then, after the switch, the variable's value is returned, or the switch statement will just return the value, w/o storing it in a variable. Also, there can be extensive code prior to the return part of it. The listed above procedure is what they call a "convenience procedure"
You can assume that performance is of high interest for the code.
Aside from readability, the ternary operator may produce unexpected results. For example, if the selected proc returns 0123, your me proc will return 83 instead. So unless you are sure that situation can never occur, it's safer to use the if command.