From bce7878f2a86f71bf643d52cde61eefc9bd96cda Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 30 Mar 2023 12:55:47 -0400 Subject: style guide: return --- docs/tcl.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'docs') diff --git a/docs/tcl.md b/docs/tcl.md index 234e5e63..0bcea651 100644 --- a/docs/tcl.md +++ b/docs/tcl.md @@ -58,6 +58,19 @@ subfolder) or printed programs. Use `try` (and `on error`) in new code. Avoid using `catch`; it's older and easier to get wrong. +#### Return + +In general, don't use `return` if it's the last statement in a code +block. Just put the statement there whose value you want to return. + +Bad: `proc add {a b} { return [expr {$a + $b}] }` +Good: `proc add {a b} { expr {$a + $b} }` + +Bad: `set x 3; return $x` +Good: `set x 3; set x` + +You should use `return` only when you actually need to return _early_. + #### Tcl datatypes Create a namespace for your datatype that is an ensemble command with -- cgit v1.2.3